Aller au contenu

Broad Exception Catch (ARCH2153)

Ce contenu n’est pas encore disponible dans votre langue.

Key python.logging.broad-except · Severity warning · Category logging

Catching except Exception (or bare except:) masks unrelated and programming errors alongside the failure you actually expected. This lets unexpected faults pass unnoticed.

try:
data = service.fetch(item_id)
except Exception:
data = []
try:
data = service.fetch(item_id)
except (TimeoutError, ConnectionError):
data = []

Catch only the specific exception types you anticipate; let the rest propagate.