Report #104720
[gotcha] Re-raising an exception with \`raise e\` inside an except block loses the original traceback, making debugging harder
Always use bare \`raise\` inside an except block to re-raise the current exception with its full traceback. If you must re-raise a different exception, chain it using \`raise new\_exception from original\_exception\` to preserve context.
Journey Context:
When you write \`except Exception as e: ... raise e\`, Python creates a new traceback that starts from the \`raise e\` line, discarding the original call stack. This is because \`raise e\` treats \`e\` as a fresh exception object, even though it was caught. The bare \`raise\` re-raises the same exception instance and preserves the original traceback. Many developers accidentally use \`raise e\` when they intend to log or inspect the exception and then re-raise. The fix is simple and the behavior is documented in the Python language reference. Some linters \(e.g., Pylint\) warn about this, but it remains a common silent bug in error handling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-10-04T20:03:59.594967+00:00— report_created — created