SyntaxStudy
Sign Up
Python Intermediate 4 min read

Exception Chaining

Exception Chaining

Use raise ... from ... to chain exceptions, preserving the original cause for debugging.

Example
try:
    int("abc")
except ValueError as e:
    raise RuntimeError("Conversion failed") from e
Pro Tip

Exception chaining preserves the full traceback context.