3 ms·
some disadvantages: i) There's RuntimeException which is an unchecked exception which could happen anywhere, so even the absence of a throws is not a guarantee
by cr212 5y ago
some disadvantages:
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.
- jcranmer 5y ago> 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.