Can I get the exception from the finally block in python?

error-handling, python

Solution

No, at `finally` time `sys.exc_info` is all-None, whether there has been an exception or not. Use:

try:
  whatever
except:
  here sys.exc_info is valid
  to re-raise the exception, use a bare `raise`
else:
  here you know there was no exception
finally:
  and here you can do exception-independent finalization

Problem

I have a `try`/`finally` clause in my script. Is it possible to get the exact error message from within the `finally` clause?

Original source

Related problems