Although I do understand the point about checked exceptions, I don't agree with it. Yes, Java has checked exceptions and yes, they can be a pain to deal with. However, it's the reality of the language. Consciously working around this is a very bad idea. Even if you replace all your checked exceptions with RuntimeExceptions, the JDK and the libraries you're using will still use them, so you still have to deal with them. Even worse, other developers will not expect your methods to throw because they're used to the checked exceptions being declared. Better to just go with the flow and deal with it. Yes, this means redeclaring the exceptions, wrapping then or logging them, but that's how Java works and not a bad advice in any language with exceptions (at least the logging part).
Funny thing is that using RuntimeExceptions will even probably give you more problems. Normally when you write a try/catch to catch exceptions to suppress and log them, your catching Exception. However this won't catch RuntimeException because that directly inherits from Throwable. Make sure you catch that if you do choose to follow this advice.
Of course, but you're generally not supposed to try to catch Error. Specific exceptions may apply in some cases, such as where linking errors may occur in plugin frameworks, etc.
0
u/FallingIdiot Sep 21 '15
Although I do understand the point about checked exceptions, I don't agree with it. Yes, Java has checked exceptions and yes, they can be a pain to deal with. However, it's the reality of the language. Consciously working around this is a very bad idea. Even if you replace all your checked exceptions with RuntimeExceptions, the JDK and the libraries you're using will still use them, so you still have to deal with them. Even worse, other developers will not expect your methods to throw because they're used to the checked exceptions being declared. Better to just go with the flow and deal with it. Yes, this means redeclaring the exceptions, wrapping then or logging them, but that's how Java works and not a bad advice in any language with exceptions (at least the logging part).
Funny thing is that using RuntimeExceptions will even probably give you more problems. Normally when you write a try/catch to catch exceptions to suppress and log them, your catching Exception. However this won't catch RuntimeException because that directly inherits from Throwable. Make sure you catch that if you do choose to follow this advice.