I have a program (not mine) that has a large try - except block. Somewhere in this block there is an exception. what is the best way to find out the exact string of code where it happens?
You can use print_exc in the except
block
import traceback
traceback.print_exc()
Example:
import traceback
try:
pass
pass
pass
pass
pass
raise NameError("I dont like your name")
pass
pass
pass
pass
pass
except Exception, e:
traceback.print_exc()
Output
Traceback (most recent call last):
File "/home/thefourtheye/Desktop/Test.py", line 8, in <module>
raise NameError("I dont like your name")
NameError: I dont like your name
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