3

I am trying to log the error that caused my process to shut down, but traceback.print_tb and traceback.print_exc don't seem to realize what the raised error is.

In other words, why does the following print 'None\n' instead of 'DivisionByZero .. etc ..'? (Edit: ..and how do I get access to the raised/handled error from within exit_fn?)

import traceback, atexit def exit_fn(): print 'exiting' if traceback.format_exc().startswith('None'): print 'why is this None?' atexit.register(exit_fn) x = 1/0 
1

1 Answer 1

1

I believe that, by the time your routine has been called, the exception has already been 'handled' (at least when I run your code, I see a traceback even if I remove your call to print one), so that there is none to be formatted at that point.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.