except-with-non-exception-classes (B030) | Ruff (original) (raw)

Added in v0.0.255 ·Related issues ·View source

Derived from the flake8-bugbear linter.

What it does

Checks for exception handlers that catch non-exception classes.

Why is this bad?

Catching classes that do not inherit from BaseException will raise aTypeError.

Example

Use instead:

[](#%5F%5Fcodelineno-1-1)try: [](#%5F%5Fcodelineno-1-2) 1 / 0 [](#%5F%5Fcodelineno-1-3)except ZeroDivisionError: [](#%5F%5Fcodelineno-1-4) ...

References