On this page
traceback.TracebackException
Prev: traceback.StackSummary | Up: traceback | Next: traceback.walk_stack
Rel: traceback.clear_frames, traceback.extract_stack, traceback.extract_tb, traceback.format_exc
Ref: docs.python.org — traceback.TracebackException
Tags: #public #python3 #stdlib #traceback
Import
import traceback
from traceback import TracebackException
Signature & Overview
traceback.TracebackException(exc_type, exc_value, exc_traceback, *, limit=None, lookup_lines=True, capture_locals=False, compact=False, max_group_width=15, max_group_depth=10, save_exc_type=True, _seen=None)
An exception ready for rendering.
Methods & Attributes
TracebackException.exc_type(...)—TracebackException.exc_typemethod/property.TracebackException.exc_type_str(...)—TracebackException.exc_type_strmethod/property.TracebackException.format(self, *, chain=True, _ctx=None, **kwargs)— Format the exception.TracebackException.format_exception_only(self, *, show_group=False, _depth=0, **kwargs)— Format the exception part of the traceback.TracebackException.from_exception(exc, *args, **kwargs)— Create a TracebackException from an exception.TracebackException.print(self, *, file=None, chain=True, **kwargs)— Print the result of self.format(chain=chain) to 'file'.
Usage
import traceback
try:
1 / 0
except ZeroDivisionError as exc:
te = traceback.TracebackException.from_exception(exc)
assert 'ZeroDivisionError' in ''.join(te.format())
Gotchas
- Best class for storing/formatting exceptions asynchronously without retaining live stack frames.
REPL Inspect
from traceback import TracebackException
help(TracebackException)
Linked from
Related notes
- tuts/python3/stdlib_module/traceback/StackSummary Linked here; links to this page; shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/walk_stack Linked here; links to this page; shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/traceback/clear_frames Linked here; shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/extract_stack Linked here; shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/extract_tb Linked here; shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/format_exc Linked here; shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/format_exception shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/format_exception_only shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/format_list shared tags: #stdlib, #traceback