traceback.print_exception
Prev: traceback.print_exc | Up: traceback | Next: traceback.print_last
Rel: traceback.clear_frames, traceback.extract_stack, traceback.extract_tb, traceback.format_exc
Ref: docs.python.org — traceback.print_exception
Tags: #public #python3 #stdlib #traceback
Import
import traceback
from traceback import print_exception
Signature & Overview
traceback.print_exception(exc, /, value=<implicit>, tb=<implicit>, limit=None, file=None, chain=True, **kwargs)
Print exception up to 'limit' stack trace entries from 'tb' to 'file'.
Usage
import io, traceback
buf = io.StringIO()
try:
1 / 0
except ZeroDivisionError as exc:
traceback.print_exception(type(exc), exc, exc.__traceback__, file=buf)
assert 'ZeroDivisionError' in buf.getvalue()
Gotchas
- Accepts single-argument
print_exception(exc)in Python 3.10+.
REPL Inspect
from traceback import print_exception
help(print_exception)
Linked from
Related notes
- tuts/python3/stdlib_module/traceback/print_exc Linked here; links to this page; shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/print_last 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