ABC-registered Exceptions are not caught as subclasses

andrew cooke andrew at acooke.org
Sat May 7 15:03:28 EDT 2011


This isn't hugely surprising, but doesn't seem to be documented.  Is it a bug, or worth raising as one, or have I misunderstood?


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>
__main__.MyException

If you assume that the ABC "register" class should work likeinheritance (as it does with issubclass and isinstance then you would, I think, have expected the exception above to have been caught.

Andrew



More information about the Python-list mailing list