Don't catch errors unless doing something actually useful with them. Even then, it's often a good idea to re-raise.
Don't catch errors unless doing something actually useful with them. Even then, it's often a good idea to re-raise.
So alongside swallowed exceptions is throwing exceptions in scenarios that were entirely recoverable, and I think in both scenarios devs just don't understand their program enough and are choosing to panic, or ignore the problem.
I think people often throw exceptions rather than write the code that handles the situation more gracefully. If you knew it could happen, then is it really an exceptional circumstance?
The most egregious thing to me is the fact that most languages let any function throw any error it wants without requiring that be documented or part of the type system or anything.
There is no rule of thumb because the scenarios are too varied and context matters.
- Sometimes what’s best for the system isn’t what’s best for your job
Fail fast is a good ethic but all to often I’ve encountered applications that are only to happy to limp along for the sake of optics. If that’s the prevailing sentiment where you work I’d recommend against violating it off your own bat.