Empty catch block swallows the exception
ID |
c.correctness.empty_catch_block |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Error Handling |
Language |
C / C++ |
Description
This catch block has an empty body, so the exception is silently discarded and the failure it signalled is lost. Handle the error (log it, recover, or translate it), or rethrow if this scope cannot handle it. If ignoring is truly intended, document why with a comment.
Rationale
This catch block has an empty body, so the exception is silently discarded and the failure it signalled is lost. Handle the error (log it, recover, or translate it), or rethrow if this scope cannot handle it. If ignoring is truly intended, document why with a comment.
The following code illustrates the pattern detected by this rule:
int emptyTypedCatch() {
// FLAGGED: Empty catch block swallows the exception
try {
throw 5;
} catch (const Exception &) {
}
return 0;
}