Exception Attributes

BaseException.__traceback__ — exception attribute

Access the traceback chain describing where an exception was raised and propagated. A traceback retains frame references, which can keep local objects alive; prefer a formatted summary for long-lived diagnostics. Assign None to detach the chain, or assign a traceback object.

Formal Syntax & Structure

python syntaxpython
error.__traceback__

Return Value

traceback | None

The attached traceback, if present.

Working Example

Example Snippetpython
try:    1 / 0except ZeroDivisionError as caught:    tb = caught.__traceback__    print(tb is not None)    print(tb.tb_frame.f_code.co_name)    caught.__traceback__ = None    print(caught.__traceback__ is None)
Python Reference