我注意到在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()