Re:On the proliferation of try, and soon, await (2020)
by jcranmer on Thursday August 26, 2021 @02:43PM
(#28318857)
> iii) IDEs offer to put try-catch { // todo } to avoid compiler errors.
This is the thing that always pissed me off. The default catch block should be to wrap it in a RuntimeException and rethrow it.
i) There's RuntimeException which is an unchecked exception which could happen anywhere, so even the absence of a throws is not a guarantee of not throwing.
ii) In order to avoid many different throws specifiers, you end up with wrapping exceptions to a smaller set of exceptions (e.g. JNDI may throw a NamingException that wraps an IOException)
iii) IDEs offer to put try-catch { // todo } to avoid compiler errors. Developers often stop thinking then, where the right thing is more often to let it throw - e.g. I've seen FileNotFound being caught and logged (at debug) and not exposed to a caller, so a UI doesn't see it, with bad results.