Report #78616
[gotcha] Re-raising exceptions leaks internal implementation details in tracebacks or creates confusing 'During handling of the above exception' messages
Use \`raise NewException\('message'\) from e\` to explicitly chain exceptions when the original error is part of the API contract, OR use \`raise NewException\('message'\) from None\` to suppress the context when the original error is an implementation detail \(e.g., catching KeyError in a JSON parser to raise YourJSONError\)
Journey Context:
By default, Python links exceptions in a chain using \`\_\_context\_\_\`. When you catch an exception and raise a new one, Python automatically sets the old exception as the context, printing 'During handling of the above exception, another exception occurred'. This leaks internals \(e.g., SQLAlchemy showing underlying DBAPI errors when you want to show a clean DomainError to users\). Using \`from None\` breaks this chain, showing only your exception. However, blind use loses debugging info, so use \`from e\` when the error is part of the API contract \(e.g., FileNotFound -> ConfigError\) to preserve the traceback for logging while presenting a clean message.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T14:33:05.796212+00:00— report_created — created