traceback.format_exception
Prev: traceback.format_exc | Up: traceback | Next: traceback.format_exception_only
Rel: traceback.clear_frames, traceback.extract_stack, traceback.extract_tb, traceback.format_exc
Ref: docs.python.org — traceback.format_exception
Tags: #public #python3 #stdlib #traceback
Import
import traceback
from traceback import format_exception
Signature & Overview
traceback.format_exception(exc, /, value=<implicit>, tb=<implicit>, limit=None, chain=True, **kwargs)
Format a stack trace and the exception information.
Usage
import traceback
try:
1 / 0
except ZeroDivisionError as exc:
lines = traceback.format_exception(type(exc), exc, exc.__traceback__)
assert 'ZeroDivisionError' in ''.join(lines)
Gotchas
- In Python 3.10+, you can pass just
traceback.format_exception(exc)(1 argument).
REPL Inspect
from traceback import format_exception
help(format_exception)
Linked from
Related notes
- tuts/python3/stdlib_module/traceback/clear_frames Linked here; links to this page; shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/extract_stack Linked here; links to this page; shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/extract_tb Linked here; links to this page; shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/format_exc Linked here; links to this page; shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/format_exception_only 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/format_list shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/format_stack shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/format_tb shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/FrameSummary shared tags: #stdlib, #traceback