kuroko/test/testReraisedExceptionTracebacks.krk
K. Lange f38a451f19 Attach and build upon partial tracebacks
If an exception is raised within a 'try', attach a traceback only up
until that 'try'. If a re-raised exception has a traceback already,
attach the new traceback "above" the existing one.
2022-07-03 20:39:07 +09:00

40 lines
850 B
Python

def foo():
try:
raise ValueError("oh no")
except Exception as e:
raise e
if True:
try:
foo()
except Exception as e:
print("Traceback entries")
for i in e.traceback:
let func, instr = i
print(f" File '{func.__file__}', line {func._ip_to_line(instr)}, in {func.__name__}")
else:
foo()
def bar(n):
if n == 3:
raise ValueError(n)
else:
bar(n+1)
if True:
try:
try:
bar(0)
except Exception as e:
raise e
except Exception as e:
print("Traceback entries")
for i in e.traceback:
let func, instr = i
print(f" File '{func.__file__}', line {func._ip_to_line(instr)}, in {func.__name__}")
else:
try:
bar(0)
except Exception as e:
raise e