It seems like the traceback returned sys.exc_info()
contains only the frames from inside the try:
block where you caught the exception from. Is there a way to get the full traceback?
To clarify, I want to get the traceback so that traceback.print_exc()
prints the same, full traceback every time it is called in this snippet (just as the last call and the sys.excepthook
printed in the end):
def a():
try:
raise ValueError
except:
traceback.print_exc()
raise
def b():
try:
a()
except:
traceback.print_exc()
raise
try:
b()
except:
traceback.print_exc()
raise
The output for this snippet is:
Traceback (most recent call last):
File "test.py", line 403, in a
raise ValueError
ValueError
Traceback (most recent call last):
File "test.py", line 410, in b
a()
File "test.py", line 403, in a
raise ValueError
ValueError
Traceback (most recent call last):
File "test.py", line 417, in <module>
b()
File "test.py", line 410, in b
a()
File "test.py", line 403, in a
raise ValueError
ValueError
Traceback (most recent call last):
File "test.py", line 417, in <module>
b()
File "test.py", line 410, in b
a()
File "test.py", line 403, in a
raise ValueError
ValueError