Getting Extended Exception Information

C

Cy Edmunds

In an exception handler I can get the error message by just converting the
Exception to a string. How do I get the entire message including the call
stack information that I see printed out with an uncaught exception?
 
B

Benjamin Niemann

Cy said:
In an exception handler I can get the error message by just converting the
Exception to a string. How do I get the entire message including the call
stack information that I see printed out with an uncaught exception?
what you are looking for is probably:

import traceback

try:
...
except:
stackdump = "".join(traceback.format_exception(sys.exc_type,
sys.exc_value, sys.exc_traceback))
print stackdump
 
D

Duncan Booth

what you are looking for is probably:

import traceback

try:
...
except:
stackdump = "".join(traceback.format_exception(sys.exc_type,
sys.exc_value, sys.exc_traceback))
print stackdump

Please note that sys.exc_type, sys.exc_value and sys.exc_traceback have
been deprecated for a long time now (they are not thread-safe). Use
sys.exc_info() instead.
 
B

Benjamin Niemann

Duncan said:
Please note that sys.exc_type, sys.exc_value and sys.exc_traceback have
been deprecated for a long time now (they are not thread-safe). Use
sys.exc_info() instead.
oh, good to know - I've been copy-and-pasting these lines around for an
even longer time ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top