
June 25, 2017
5:21 p.m.
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-th... 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