Skip to content

SCR113: except-order

Exception class caught after a broader one

Code SCR113
Name except-order
Category Scripts (SCR)
Default severity warning
Enabled by default yes
Fix available no
ign-lint equivalent none

Reports an except clause naming a builtin exception class that an earlier clause of the same try already catches, because it names the same class or a base class (Exception before ValueError, LookupError before KeyError). Only builtin exception classes are compared (the hierarchy was checked against Jython 2.7); Java exception classes are not.

The later handler never runs: the earlier, broader handler takes every exception it would have handled.

try:
value = int(payload["value"])
except Exception:
value = None
except KeyError:
value = 0

Use instead:

try:
value = int(payload["value"])
except KeyError:
value = 0
except Exception:
value = None

Corresponds to E0701 bad-except-order.


Generated from the rule metadata by iglint generate-docs; iglint rule SCR113 prints the same page in the terminal. Source: docs/rules/SCR113.md.