引发...来自:使用pdb移入已包装异常的堆栈

时间:2019-04-03 14:45:58

标签: python python-3.x

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()的局部变量?

0 个答案:

没有答案