SyntaxStudy
Sign Up
Python Intermediate 3 min read

The Traceback Module

The Traceback Module

The traceback module lets you log or display exception tracebacks programmatically.

Example
import traceback

try:
    1 / 0
except ZeroDivisionError:
    traceback.print_exc()
    # or: text = traceback.format_exc()
Pro Tip

Use traceback.format_exc() to log errors to a file.