python exceptions: how to print all debug info for nested try?
I have code:
try:
print test.qwerq]
try:
print test.sdqwe]
except:
pass开发者_Python百科
except:
pass
How to print debug info for all errors in nested try ?
Re-raise exceptions.
try:
print test[qwerq]
try:
print test[qwe]
except:
# Do something with the exception.
raise
except:
# Do something here too, just for fun.
raise
It should be noted that in general you don't want to do this. You're better off not catching the exception if you're not going to do anything about it.
If you want to just print the call stack and not crash, look into the traceback module.
精彩评论