I don't know what it's called, but when I'm in the python live interpreter, I get a trail of statements in the form 'File , line ' etc, showing all the places where something went wrong so I can pinpoint the origin. Is this information an attribute of the exception that I can access? I'm looking for some solution like:
try:
do_something_wrong()
except Exception as e:
print e.really_useful_information
What should I use as 'really_useful_information'? If it isn't possible, how else could I access this information while continuing to run the program?
You could use traceback.print_exc():
import traceback
try:
...
except Exception as e:
traceback.print_exc()
What you are looking for is called a stack trace, if I understand you correctly. Take a look at the traceback module: http://docs.python.org/2/library/traceback.html Specifically traceback.print_exception() and traceback.print_exc().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With