Dropped Exception
ID |
java.dropped_exception |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Java |
Tags |
CWE:391, reliability |
Description
Reports catch blocks where the caught exception variable is never referenced inside the block body. A silently swallowed exception hides failures and makes debugging extremely difficult.
Rationale
When an exception is caught but its variable is never used, the exception information (message, stack trace, cause chain) is lost. This pattern often indicates that the developer intended to handle the error but forgot, or copied the catch block from elsewhere without adapting it.
// Bad -- exception is silently swallowed
try {
connection.close();
} catch (IOException e) {
// e is never referenced
retryLater();
}
Remediation
At a minimum, log the exception. If the exception is intentionally ignored, name the variable ignored (or any name starting with ignore) so the intent is explicit, or add a logger call in the catch body.
// Good -- exception is logged
try {
connection.close();
} catch (IOException e) {
log.warn("Failed to close connection", e);
retryLater();
}
// Also accepted -- intent to ignore is explicit
try {
connection.close();
} catch (IOException ignored) {
retryLater();
}
Configuration
| Property | Default | Description |
|---|---|---|
|
|
When |