Python 3具有从构造中引发的优点...
def f():
assert False
def g():
try:
f()
except Exception as e:
raise Exception('this is a wrapper') from e
g()
上面打印出:
Traceback (most recent call last):
File "raise_from.py", line 6, in g
f()
File "raise_from.py", line 2, in f
assert False
AssertionError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "raise_from.py", line 10, in <module>
g()
File "raise_from.py", line 8, in g
raise Exception('this is a wrapper') from e
Exception: this is a wrapper
哪一个非常好和整洁。 但是,当我尝试使用命令行pdb或PyCharm调试程序时,我找不到跳到包装异常堆栈上的任何方法。在引发原始AssertionError的那一刻,如何检索f()的局部变量?