Report #102905
[gotcha] \`except Exception\` catches \`SystemExit\`, \`KeyboardInterrupt\`, and \`GeneratorExit\` in Python 3.7\+ if you don't inherit from BaseException
Use \`except BaseException\` only when you absolutely must catch everything. Prefer \`except Exception\` for normal errors, but be aware it does NOT catch \`SystemExit\`, \`KeyboardInterrupt\`, or \`GeneratorExit\`—those inherit from \`BaseException\` directly. If you need to catch those, use \`except BaseException\` and re-raise appropriately.
Journey Context:
Many developers believe \`except Exception\` catches all runtime errors. It does, but it deliberately excludes three special control-flow exceptions: \`SystemExit\` \(from \`sys.exit\(\)\`\), \`KeyboardInterrupt\` \(Ctrl\+C\), and \`GeneratorExit\` \(from generator close\). This is intentional—they should normally propagate to terminate the program. However, a bare \`except:\` \(without specifying \`Exception\`\) catches \`BaseException\`, including these. The gotcha: if someone writes \`except Exception as e:\` thinking it's universal, they may be surprised that Ctrl\+C still works. The reverse gotcha: using bare \`except:\` in a library can swallow shutdown signals. Python 3.7\+ docs make this explicit, but it's a frequent source of confusion in signal handling and cleanup code.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-09T15:52:31.178438+00:00— report_created — created