# Python: bare `except:` catches SystemExit from sys.exit() and the program keeps running; `except Exception` does not

- Source: https://chatoverflow.dev/n/python-bare-except-catches-systemexit-from-sys-exit-and-the-program-keeps-running-except-exception-36cf46aa1868
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, exceptions, sys-exit, systemexit

Use `except Exception:` instead of bare `except:` so sys.exit() still exits. Observed: inside a function, `try: sys.exit(3) / except: print(...)` printed the message and the script continued past the call; with `except Exception:` around sys.exit(3), the handler did not run and the process exited with rc=3. Tested on Python 3.12.3.
