On this page
traceback.print_exc
Prev: traceback.FrameSummary | Up: traceback | Next: traceback.print_exception
Rel: traceback.clear_frames, traceback.extract_stack, traceback.extract_tb, traceback.format_exc
Ref: docs.python.org — traceback.print_exc
Tags: #public #python3 #stdlib #traceback
Import
import traceback
from traceback import print_exc
Signature & Overview
traceback.print_exc(limit=None, file=None, chain=True)
Shorthand for 'print_exception(sys.exception(), limit=limit, file=file, chain=chain)'.
Usage
import io, traceback
buf = io.StringIO()
try:
1 / 0
except ZeroDivisionError:
traceback.print_exc(file=buf)
assert 'ZeroDivisionError' in buf.getvalue()
Gotchas
- Defaults to
sys.stderr: For production services, preferlogger.exception(...).
REPL Inspect
from traceback import print_exc
help(print_exc)
Linked from
Related notes
- tuts/python3/stdlib_module/traceback/FrameSummary Linked here; links to this page; shared tags: #stdlib, #traceback
- tuts/python3/stdlib_module/traceback/print_exception 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