Answer the question
In order to leave comments, you need to log in
Why is the full exception stack not visible?
I need a function that catches the exception stack. However, it turned out that a simple method like
try:
raising_func()
except Exception:
_, _, tb = sys.exc_info()
#перехватывающая функция
def stack_capture(func):
try:
func()
except Exception:
_, _, tb = sys.exc_info()
return tb
#вызов
def some_function()
my_tb = stack_capture(raising_func)
Answer the question
In order to leave comments, you need to log in
returns only the top exception thrown inside stack_capture() itself. Why is this happening and is it possible to get the whole stack?
my_tb = stack_capture(raising_func)
t = my_tb
while t:
print(t.tb_frame, t.tb_lineno, t.tb_lasti)
t = t.tb_next
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question