Python Bare Except vs Exception: What Each Catches
A bare except catches BaseException and can hide KeyboardInterrupt or SystemExit. See why except Exception is the safer default in Python.

The difference between a bare except: and except Exception comes down to one rule: a bare except: catches BaseException, while except Exception catches only the Exception hierarchy. That single difference determines whether your handler receives KeyboardInterrupt, SystemExit, and GeneratorExit — exceptions that most application code should let propagate.
What a Bare Except Catches
When you write:
try:
run_task()
except:
log_failure()Python treats the bare except as except BaseException. The handler runs for every exception type in the language, including ones that normally should terminate the process. Pressing Ctrl+C during run_task() raises KeyboardInterrupt, which is a subclass of BaseException but not of Exception. The bare handler intercepts it, logs it as a failure, and execution continues as if nothing happened.
The same applies to SystemExit, which is raised by sys.exit(). A bare except swallows the exit request, so a script that was supposed to terminate cleanly keeps running. A bare handler also catches GeneratorExit, which is raised while a generator is being closed.
What except Exception Catches
try:
run_task()
except Exception:
log_failure()Exception is the base class for most errors application code is expected to handle: ValueError, TypeError, KeyError, OSError, RuntimeError, and so on. It deliberately excludes the BaseException subclasses that represent control flow rather than ordinary errors, such as KeyboardInterrupt, SystemExit, and GeneratorExit.
This makes except Exception the safer default. It still catches a broad range of failures, but it lets process-level signals and exit requests propagate. A user pressing Ctrl+C interrupts the program as expected, and sys.exit() still terminates the process.
Why the Difference Matters in Practice
Consider a long-running worker that processes a queue:
while True:
try:
item = queue.get()
process(item)
except:
time.sleep(1)If an operator sends a shutdown signal that raises KeyboardInterrupt, the bare except swallows it and the worker continues looping. The process cannot be stopped cleanly. Changing the handler to except Exception allows the interrupt to propagate, so the worker exits and a supervisor can restart it.
The same issue appears in scripts that call sys.exit() on a fatal error. A bare except converts an intentional exit into a logged error and continues execution, potentially leaving the program in an inconsistent state.
When a Bare Except Might Be Justified
There are rare cases where catching BaseException is deliberate. A cleanup routine that must run before the interpreter shuts down, such as releasing a lock or flushing a buffer, may need to handle every exception type. Even then, the handler should re-raise after cleanup:
try:
work()
except BaseException:
cleanup()
raiseNotice that this uses except BaseException explicitly rather than a bare except. Being explicit makes the intent visible to reviewers and avoids the ambiguity of the bare form. The raise statement without arguments re-raises the original exception, so the process still terminates with the correct traceback.
Writing Handlers That Preserve the Original Failure
A common pattern is to catch one exception and raise a different one without making the original the direct cause:
try:
parse_config(path)
except Exception:
raise ValueError("configuration failed")Python automatically keeps the original exception as the __context__ of the new one, so the traceback still shows both errors. But the new exception does not identify the original as its direct cause. Use from to make that relationship explicit:
try:
parse_config(path)
except Exception as exc:
raise ValueError("configuration failed") from excThe from clause sets the __cause__ attribute on the new exception, so the traceback shows the new error and labels the original failure as its direct cause. Without from, the original exception still appears as context during handling; with from, the causal chain is explicit, which helps when debugging handlers that catch broad exception types.
Maintainability and Debugging Concerns
A bare except makes code harder to reason about because the reader cannot tell which failures the author intended to handle. When a handler catches KeyboardInterrupt or SystemExit, it changes the control flow of the entire program. Debugging a process that refuses to shut down often leads back to a bare except that swallowed the exit signal.
except Exception still has a broad scope, so in production code it is usually better to catch specific exception types. The choice between bare except and except Exception is the first level of narrowing: it separates process-level control flow from ordinary errors. After that, catching ValueError or KeyError explicitly makes the handler's purpose clear and prevents unrelated failures from being masked.
Try matching browser tools
All toolsSmall utilities that fit Python work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Python guides
All Python guidesPython iter(): How the Built-in Function Works
Explains Python's iter() built-in: how it creates iterators, the two-argument sentinel form, custom iterator classes, and common edge cases.
Python Pika: Queues, Exchanges, Routing Keys, and Acknowledgements
Learn how to use Python's Pika client with RabbitMQ: declare queues and exchanges, publish with routing keys, consume messages, and handle acknowledgements reliably.
Python Kafka: kafka-python vs Confluent Client
python kafka python vs confluent kafka: Compare kafka-python and Confluent Kafka Python clients: API differences, performance, feature coverage, and when to choose eac...
Python Kafka Offsets, Partitions, and Manual Commits
Learn how Kafka offsets and partitions work and how to manually commit offsets in Python consumers with kafka-python and confluent-kafka. Covers sync vs async commits, rebalances, and seeking.
More in Python
All Python guidesThe guides filed next to this one in Python, in library order.