Why is a bare `except:` (or `except Exception: pass`) dangerous?
BeginnerConceptExceptions, context managers, files & logging
Answer
Bare except: catches BaseException, including KeyboardInterrupt and SystemExit, so Ctrl-C and sys.exit() stop working. except Exception: pass swallows every bug, typos included, and the script reports success while doing nothing. Catch the narrowest exception you can actually handle, log it with context, and re-raise anything you cannot handle. If you must catch broadly at the top level, log with log.exception(...) and exit non-zero.
More on Exceptions, context managers, files & logging
How does `try` / `except` / `else` / `finally` work?BeginnerWhat is exception chaining, and what is `raise ... from`?IntermediateWhen should you define custom exception classes?IntermediateWhat is the EAFP vs LBYL style, and which does Python prefer?IntermediateHow does a `with` statement work, and why use it for files?BeginnerHow do you write your own context manager?Advanced