Getting Extended Exception Information

Benjamin Niemann b.niemann at betternet.de
Wed Jul 21 05:31:06 EDT 2004


Duncan Booth wrote:
> Benjamin Niemann <b.niemann at betternet.de> wrote in
> news:cdl694$jqu$1 at online.de: 
> 
> 
>>Cy Edmunds wrote:
>>
>>>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
> 
> 
> 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 ;)



More information about the Python-list mailing list