This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author acooke
Recipients acooke
Date 2011-05-08.08:53:42
SpamBayes Score 1.6653345e-16
Marked as misclassified No
Message-id <>

In general, registering a class with an ABC is equivalent to making it a subclass (isinstance and issubclass are patched through ABCMeta).  However, this does not work for exceptions (see example below, where exception is not caught).

This doesn't seem terribly surprising to me - I imagine that checking would slow down exception handling - but I couldn't find any documentation (and posting on c.l.p didn't turn up anything either).

So I thought I would raise it here - perhaps there is a possible fix (my obscure use case is that I have a backtracking search; backtracking occurs when a certain exception is encountered; making that exception an ABC and allowing existing exceptions to be registered with it allows the search to work with existing code without a wrapper that catches and translates exceptions that should trigger a backtrack).  Or perhaps the docs could be extended.  Or perhaps I've misunderstood something...


Python 3.2 (r32:88445, Feb 27 2011, 13:00:05) 
[GCC 4.5.0 20100604 [gcc-4_5-branch revision 160292]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from abc import ABCMeta
>>> class RootException(Exception,metaclass=ABCMeta): pass
>>> class MyException(Exception): pass
>>> RootException.register(MyException)
>>> try:
...     raise MyException
... except RootException:
...     print('caught')
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
Date User Action Args
2011-05-08 08:53:43acookesetrecipients: + acooke
2011-05-08 08:53:43acookesetmessageid: <>
2011-05-08 08:53:43acookelinkissue12029 messages
2011-05-08 08:53:42acookecreate