Message253963
[Avoiding UTF-8 error]
This is an interesting idea that never occurred to me. It would be nice to support it if the performance impact isn’t a problem. By the sound of Issue 12029, performance is barely affected until you actually try to catch a “virtual exception”. So the impact of changing from subclass to instance checking shouldn’t be much worse if we do it right.
I agree this would be a new feature for a new release, not for 2.7 or 3.5.
BTW here’s another approach using the same sys.exc_info() hack that also works in Python 3:
>>> def catch_not_implemented():
... '''Helper to catch "API not implemented" exceptions'''
... [_, exc, _] = sys.exc_info()
... if isinstance(exc, NotImplementedError):
... return BaseException # Catch the exception
... if isinstance(exc, EnvironmentError) and exc.errno == ENOSYS:
... return BaseException # Catch the exception
... if isinstance(exc, HTTPError) and exc.code == HTTPStatus.NOT_IMPLEMENTED:
... return BaseException # Catch the exception
... return () # Don't catch the exception
...
>>> try: raise OSError(ENOSYS, "Dummy message")
... except catch_not_implemented() as err: print(repr(err))
...
OSError(38, 'Dummy message') |
|
Date |
User |
Action |
Args |
2015-11-03 03:04:42 | martin.panter | set | recipients:
+ martin.panter, r.david.murray, sjoerdjob |
2015-11-03 03:04:41 | martin.panter | set | messageid: <1446519881.95.0.729972739623.issue25537@psf.upfronthosting.co.za> |
2015-11-03 03:04:41 | martin.panter | link | issue25537 messages |
2015-11-03 03:04:41 | martin.panter | create | |
|