On Sat, Jun 24, 2017 at 11:45:25PM +1000, Nick Coghlan wrote: > While I used to think that, I'm no longer sure it's true, as it seems > to me that a `contextlib.convert_exception` context manager could help > with both of them.
Here is a recipe for such a context manager which is also useable as a decorator: https://code.activestate.com/recipes/580808-guard-against-an-exception-in-the-wrong-place/ or just https://code.activestate.com/recipes/580808 It should work with Python 2.6 through 3.6 and later. try: with exception_guard(ZeroDivisionError): 1/0 # raises ZeroDivisionError except RuntimeError: print ('ZeroDivisionError replaced by RuntimeError') -- Steve _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/