Message135521
Hi,
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...
Cheers,
Andrew
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 |
|
Date |
User |
Action |
Args |
2011-05-08 08:53:43 | acooke | set | recipients:
+ acooke |
2011-05-08 08:53:43 | acooke | set | messageid: <1304844823.89.0.48444500115.issue12029@psf.upfronthosting.co.za> |
2011-05-08 08:53:43 | acooke | link | issue12029 messages |
2011-05-08 08:53:42 | acooke | create | |
|