Report #91448
[gotcha] bare except: clause catches KeyboardInterrupt and SystemExit
Always catch \`Exception\` instead of bare \`except:\` or \`except BaseException:\`. Only catch \`BaseException\` if you explicitly intend to handle program termination \(e.g., logging before exit\) and always re-raise \`SystemExit\` and \`KeyboardInterrupt\` immediately.
Journey Context:
A bare \`except:\` clause catches \`BaseException\`, not \`Exception\`. This includes \`SystemExit\` \(raised by \`sys.exit\(\)\`\), \`KeyboardInterrupt\` \(Ctrl\+C\), and \`GeneratorExit\`. Silently catching these prevents proper program termination, ignores user interrupt signals, and corrupts generator cleanup \(GeneratorExit must not be suppressed\). The correct pattern is \`except Exception:\` to catch only application-level errors. If you must catch BaseException \(e.g., for cleanup in a top-level loop\), you must explicitly check \`if isinstance\(e, \(SystemExit, KeyboardInterrupt\)\): raise\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:05:13.080067+00:00— report_created — created