没有异常处于活动状态时,Python 3跟踪失败

时间:2012-02-22 22:16:33

标签: python-3.x stack-trace traceback

我注意到在Python2中,当我尝试转储异常堆栈跟踪,但没有活动异常时,它会打印None

Python 2.7.2+ (default, Oct  4 2011, 20:06:09) 
>>> import traceback
>>> traceback.print_exc()
None

但Python3因内部问题而失败:

Python 3.2.2 (default, Sep  5 2011, 21:17:14) 
>>> import traceback
>>> traceback.print_exc()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.2/traceback.py", line 259, in print_exc
    print_exception(etype, value, tb, limit, file, chain)
  File "/usr/lib/python3.2/traceback.py", line 155, in print_exception
    for value, tb in values:
  File "/usr/lib/python3.2/traceback.py", line 122, in _iter_chain
    cause = exc.__cause__
AttributeError: 'NoneType' object has no attribute '__cause__'

这是Python中的错误,还是我应该在调用print_exc()

之前测试某些条件

1 个答案:

答案 0 :(得分:3)

That is a bug。可能会决定应该引发错误,但这肯定是错误的错误。