Hacker News new | ask | show | jobs
by cleaver 4562 days ago
Unfortunately, "Don't do X" is better click bait than "You should think carefully when you want to do X".

There will be cases where you want to do "catch {}" — you don't always have control over the exceptions thrown by a lower-level library. It might be good to create a standard where you log them conditionally, or something that could aid in troubleshooting.

2 comments

True, but as a developer, I expect a comment inside your empty catch block telling me why it is justified. I can't remember ever seeing one...
Oddly, I have seldom seen an empty catch {} without a comment, though often it was simply to point out that, yes, this is intentional. Even that is better than leaving me wondering if the code is just unfinished.
Yes, in my front controller I wanted to log to the filesystem & email exceptions. The email library threw it's own exceptions, which I wanted to ignore with "catch {}"... if email was down, and I already logged the exception, there's nothing left to do.