Python Debugging Cheat Sheet/Get exception info tuple

Access exception type, value, and traceback explicitly.

Section: Tracebacks and Exceptions

Get exception info tuple

python
python
import sys

try:
    risky_call()
except Exception:
    exc_type, exc_value, exc_tb = sys.exc_info()

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Tracebacks and Exceptions
Print the current exception traceback
Dump the active exception traceback in an except block.
OpenIn sheetpythonsame section
Format exception as a string
Capture traceback output for logs or APIs.
OpenIn sheetpythonsame section
Preserve context with raise from
Chain exceptions to keep original failure context.
OpenIn sheetpythonsame section
Enable faulthandler
Print Python tracebacks on fatal errors like segfaults.
OpenIn sheetpythonsame section
Enable faulthandler from CLI
Turn on fatal error tracebacks without code changes.
OpenIn sheetbashsame section
Show default warnings
Enable warnings that may help reveal bad behavior.
OpenIn sheetbashsame section