Skip to content

default-except-not-last

Pythoncorrectnessno fixdefault: warnpython/ruff

Reports a bare except: that is followed by another handler of the same try.

A bare except: catches everything, so the handlers after it can never run. Python rejects the file with SyntaxError: default 'except:' must be last.

To fix, put the bare except: last, or better, name the exceptions it should catch.

Reported
A = B = 1
try:
pass
except:
pass
except A:
pass
...
python:
lint:
rules:
default-except-not-last: warn # off, warn (default), error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line default-except-not-last in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff F707 full