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 |
What it does
Section titled “What it does”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.
Why is this bad?
Section titled “Why is this bad?”The later handler never runs: the earlier, broader handler takes every exception it would have handled.
Example
Section titled “Example”try: value = int(payload["value"])except Exception: value = Noneexcept KeyError: value = 0Use instead:
try: value = int(payload["value"])except KeyError: value = 0except Exception: value = Nonepylint
Section titled “pylint”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.