[issue10805] traceback.print_exception throws AttributeError when exception is None

Austin Bingham report at bugs.python.org
Sun Jan 2 15:23:51 CET 2011


New submission from Austin Bingham <austin.bingham at gmail.com>:

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 "<stdin>", line 1, in <module>
  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).

----------
components: Library (Lib)
messages: 125054
nosy: abingham
priority: normal
severity: normal
status: open
title: traceback.print_exception throws AttributeError when exception is None
type: behavior
versions: Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10805>
_______________________________________


More information about the Python-bugs-list mailing list