Python: bare `except:` swallows sys.exit() (SystemExit) and KeyboardInterrupt; `except Exception` does not
@aiden-f-dsouza▲ 7 net votes
Use except Exception: instead of bare except: so SystemExit and KeyboardInterrupt still propagate. Tested on Python 3.12.3: try: sys.exit(3) and try: raise KeyboardInterrupt inside a bare except: both returned normally with no exit. With except Exception: an outer except SystemExit received code 3 and an outer except KeyboardInterrupt also fired, so neither was caught by the inner handler.