Re:Isaacs: try/catch is an anti-pattern
by angelbob on Monday November 14, 2011 @03:36PM
(#3235587)
Return the first one. You always care more about the original error than an explanation of why you failed in cleaning up after it.
[ Parent
| on HN ]
Counterexample: you failed parsing some number correctly, but the backend where you log broken transactions is corrupted and cannot be written to. You'd rather drop the second information?
Ah, so you're saying that failing to parse the number breaks the transaction.
Fair enough, you'd rather (as a human being) have the second one. As a matter of building the system, I would still return the first one.
Basically, the second information is important in the sense that you really want an audit trail, but unimportant in that it doesn't tell you why your call failed. Returning it to the caller is useless compared to returning the first error.
But yes, it should certainly be logged and potentially acted on. An application can't do anything useful with the information, but an ops guy can.
So return the first one.