Ir al contenido

Broad Exception Catch (ARCH2153)

Esta página aún no está disponible en tu idioma.

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.