Ir al contenido

Broad Exception Catch (ARCH4153)

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

Key java.logging.catch-generic-exception · Severity info · Category logging

Catching the most general type such as Exception or Throwable silently absorbs unexpected errors (for example a NullPointerException) and masks the real problem. Catch only the specific types you can handle.

try {
return parse(input);
} catch (Exception e) {
log.warn("Parse failed", e);
return fallback;
}
try {
return parse(input);
} catch (NumberFormatException e) {
log.warn("Invalid number format: {}", input, e);
return fallback;
}

Catch only the specific exception types you can meaningfully handle instead of Exception/Throwable.