Issue 10805: traceback.print_exception throws AttributeError when exception is None (original) (raw)

traceback.print_exception() will throw an AttributeException if value is None and chain is True. This is because _iter_chain assumes that the exception object has a __cause__ attribute. You can trigger this by trying for format a non-existent exception:

import logging, sys logging.Formatter().formatException(sys.exc_info()) Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3.1/logging/init.py", line 418, in formatException traceback.print_exception(ei[0], ei[1], ei[2], None, sio) File "/usr/lib/python3.1/traceback.py", line 155, in print_exception for value, tb in values: File "/usr/lib/python3.1/traceback.py", line 122, in _iter_chain cause = exc.cause

This is assuming that sys.exc_info() returns (None, None, None).

Well, under 2.x, print_traceback(None, None, None) would just print "None", but I'm not sure that's a supported use case.