Question

I noticed that in Python2 when I try to dump the exception stack trace, but there's no active exception, it prints None:

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

But Python3 fails with some internal problem:

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__'

Is this a bug in Python, or should I always test for some condition before calling print_exc()

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top