Skip to content

blind-except (BLE001)#

Derived from the flake8-blind-except linter.

What it does#

Checks for except clauses that catch all exceptions.

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#

try:
    foo()
except BaseException:
    ...

Use instead:

try:
    foo()
except FileNotFoundError:
    ...

References#