raise ... from ... sets cause and shows the full traceback chain
When you raise a new exception while handling another, Python automatically sets the new exception's context to the original, and both tracebacks appear with a 'During handling of the above exception, another exception occurred' message. That is implicit chaining. Explicit chaining with raise X from Y sets cause to Y and replaces the message with 'The above exception was the direct cause of the following exception'. Use from when the new exception is a deliberate translation of the original, and from None when you genuinely want to suppress the context, for example to hide an internal error detail at an API boundary. The cause chain is what makes production debugging tractable: the top-level error tells you what failed, and the chain tells you why.
context is set automatically when raising inside an except block; cause is set explicitly with raise ... from ....
raise X from Y makes the translation explicit and keeps Y visible in the traceback.
raise X from None suppresses the implicit context. Use this sparingly and document why.
Always log with exc_info=True or log the full formatted exception; a bare message loses the chain.
Trade-off: leaking internal exceptions through public APIs can expose sensitive details. Translate at the boundary and use from None only when required.
Common mistake: raising a new exception inside except without preserving the original, which makes debugging a guessing game.
Version note: exception chaining and cause/context were introduced in PEP 3134 (Python 3.0).
0-2 years experience
2-5 years experience
5-8 years experience
8+ years experience