我在上下文管理器中捕获异常,但是我没有看到所有级别的重新启动异常。谁知道如何改善这个?
import traceback
def f():
try:
raise Exception("Interesting")
except Exception as e:
raise Exception("Exc {} raised".format(e))
class Try():
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
print("Exception {} raised".format(exc_val))
print("".join(traceback.format_tb(exc_tb, 100)))
return True
with Try():
f()
在这里,我还希望在回溯中看到“有趣”异常(第5行)的代码行,但是我得到了
Exception Exc Interesting raised raised
File "try_test.py", line 19, in <module>
f()
File "try_test.py", line 7, in f
raise Exception("Exc {} raised".format(e))