Martin Panter added the comment: [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') ---------- dependencies: +Catching virtual subclasses in except clauses nosy: +martin.panter versions: -Python 2.7, Python 3.5 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25537> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com