Swallowed exception
The failure is caught and the caller is told nothing went wrong.
What it looks like
- An empty
catch, or one that only logs. - A rethrow deleted from a catch block.
catch { return partial; }wherepartialis whatever had been built so far.
Why it survives review
The code looks more robust, not less: there is a try, there is a catch, somebody clearly thought about failure. And on every input that does not fail — which is nearly all of them — it behaves identically. The damage is that a partial result propagates as though it were complete.
How to see it
- For every catch, ask what the caller now believes. If the answer is 'that it worked', the catch is a defect.
- Distinguish handling an error from hiding one. Logging is not handling.
- Check that the value returned from a catch is distinguishable from a real result.
A minimal pair
Correct
catch (error) {
log(error);
throw error;
}
Defective
catch (error) {
log(error);
}
On a failing input the correct build throws; the defective one returns the half-built result.
Practise it
1 diff in the corpus carry this class. They are not listed, because knowing which diff contains what would make finding it a comprehension question about this page.
Go to the exercises