Dropped Exception
ID |
kotlin.dropped_exception |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Kotlin |
Tags |
CWE:391, error-handling, exception |
Description
Reports catch blocks whose body never references the caught exception variable.
The catch block may contain code, but if the exception variable itself is never used — not
logged, not re-thrown, not inspected — the exception information is effectively discarded.
Use _ as the parameter name to document that the suppression is intentional.
Rationale
// Bad — exception e is caught but ignored; retry() loses the root cause
try {
connect()
} catch (e: IOException) { // FLAW
retry()
}
// Good — exception logged before retry
try {
connect()
} catch (e: IOException) {
logger.warn("Connection failed, retrying", e)
retry()
}
// OK — intentional ignore with _ convention
try {
connect()
} catch (_: IOException) {
retry()
}