How to determine if an exception was raised once you’re in the finally block?
Using a contextmanager You could use a custom contextmanager, for example: class DidWeRaise: __slots__ = (‘exception_happened’, ) # instances will take less memory def __enter__(self): return self def __exit__(self, exc_type, exc_val, exc_tb): # If no exception happened the `exc_type` is None self.exception_happened = exc_type is not None And then use that inside the try: try: … Read more