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 martin.panter
Recipients martin.panter, r.david.murray, sjoerdjob
Date 2015-11-03.03:04:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1446519881.95.0.729972739623.issue25537@psf.upfronthosting.co.za>
In-reply-to
Content
[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')
History
Date User Action Args
2015-11-03 03:04:42martin.pantersetrecipients: + martin.panter, r.david.murray, sjoerdjob
2015-11-03 03:04:41martin.pantersetmessageid: <1446519881.95.0.729972739623.issue25537@psf.upfronthosting.co.za>
2015-11-03 03:04:41martin.panterlinkissue25537 messages
2015-11-03 03:04:41martin.pantercreate