【发布时间】:2014-01-07 19:10:15
【问题描述】:
考虑以下代码和回溯:
>>> try:
... raise KeyboardInterrupt
... except KeyboardInterrupt:
... raise Exception
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
KeyboardInterrupt
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
Exception
>>>
我只想打印最近的回溯(引发Exception 的回溯)。
如何实现?
从上面的示例中,我想打印以下内容,就好像在 except 子句之外调用了 raise Exception。
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
Exception
【问题讨论】:
-
“get”是指获取异常对象,还是说不打印上下文信息?如果你指的是第二种,你想要某种全局解释器设置,还是适用于特定异常的东西?
标签: python python-3.x traceback