# Python Gotchas ## `sys.exit()` inside bare `except: pass` is swallowed **Symptom:** A loop that should terminate on first match with `sys.exit(0)` kept iterating and printing multiple lines. **Cause:** `sys.exit()` raises `SystemExit`, which is a `BaseException`. A bare `except:` (or `except Exception:`) inside the loop body catches it and continues iteration. **Fix:** Use `break` instead of `sys.exit()` when the exit is inside an exception handler, or narrow the except clause to the specific exception you care about (e.g., `except (KeyError, ValueError):`). Never use bare `except:` — it masks `SystemExit`, `KeyboardInterrupt`, and real bugs.