blind-except (BLE001)
Added in v0.0.127 · Related issues · View source
Derived from the flake8-blind-except linter.
What it does
Checks for except clauses that catch all exceptions. This includes
except BaseException and except Exception.
Why is this bad?
Overly broad except clauses can lead to unexpected behavior, such as
catching KeyboardInterrupt or SystemExit exceptions that prevent the
user from exiting the program.
Instead of catching all exceptions, catch only those that are expected to
be raised in the try block.
Example
Use instead:
Exceptions that are re-raised will not be flagged, as they're expected to be caught elsewhere:
Exceptions that are logged via logging.exception() or are logged via
logging.error() or logging.critical() with exc_info enabled will
not be flagged, as this is a common pattern for propagating exception
traces: