Python traceback Module
Example
Format exception traceback:
import traceback
try:
result = 10 / 0
except ZeroDivisionError:
tb = traceback.format_exc()
print('Exception caught and formatted')
Try it Yourself »
Definition and Usage
The traceback module extracts, formats, and prints stack traces of Python exceptions.
Use it to log errors, create detailed error reports, or analyze exception information programmatically.
Members
Member | Description |
---|---|
TracebackException | Class representing a traceback. |
extract_stack() | Extract stack trace from current call stack. |
extract_tb() | Extract traceback from exception. |
format_exc() | Format current exception as a string. |
format_exception() | Format exception information as a list of strings. |
format_tb() | Format traceback as a list of strings. |
print_exc() | Print exception information to stderr. |
print_tb() | Print traceback to file. |