Broad Exception Catch (ARCH4153)
هذا المحتوى غير متوفر بلغتك بعد.
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.
Incorrect
Section titled “Incorrect”try { return parse(input);} catch (Exception e) { log.warn("Parse failed", e); return fallback;}Correct
Section titled “Correct”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.