Ir al contenido

Empty Catch Block (ARCH2150)

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

Key python.logging.empty-except-block · Severity error · Category logging

An except block with an empty body (or only comments) silently swallows the exception. This hides real failures and makes problems almost impossible to diagnose.

try:
value = int(user_input)
except ValueError:
pass
import logging
logger = logging.getLogger(__name__)
try:
value = int(user_input)
except ValueError:
logger.warning("Invalid integer input: %r", user_input)
value = 0

Log the exception at minimum; produce a meaningful default or re-raise where possible.