redline
MediumError handlingbroad-except

except Exception

except Exception. except Exception catches every bug in the block, not just the failure you expect.

This is how the comment reads inline, under the flagged line.

Why it matters

Catching Exception treats a typo, a None and a network error the same way. Bugs get handled as if they were expected failures.

What to do

Catch the exceptions this block can actually raise, or re-raise after cleanup.

Examples

Flagged
try:
    sync()
except Exception:
    retry()
Better
try:
    sync()
except (TimeoutError, ConnectionError):
    retry()

What it catches

It reads the shape of the code: functions, blocks, loops and calls. Languages: Python. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.

Flagged

try:
    go()
except Exception:
    retry()

Left alone

try:
    go()
except Exception:
    cleanup()
    raise

Research

Bare `except:`, `except Exception`, and a re-raise that drops the cause. It catches bugs you did not expect along with the error you did, and loses the original traceback.

Turn it off or change it

In a config file for the CLI, or in the API's rules field:

{
  "rules": {
    "disable": [
      "broad-except"
    ],
    "severity": {
      "broad-except": "low"
    }
  }
}

Read the source or report a false positive.