4 ms·
Why does everyone seem to think this a black-and-white issue? Checked exceptions are appropriate for some things, unchecked exceptions are appropriate for other
by vilya 17y ago
Why does everyone seem to think this a black-and-white issue? Checked exceptions are appropriate for some things, unchecked exceptions are appropriate for others. Use the right tool for the job.
Some parts of Java's API have made poor decisions in their use of checked exceptions (the close methods on file input streams and database connections, for example), but that doesn't invalidate the concept.
Correct use of checked exceptions helps create more solid code with less testing required, because the compiler is able to do checks that would otherwise have to be written into unit tests. Incorrect use of checked exceptions is what leads to all of the objections I've seen listed here.
- mechanical_fish 17y agoWhy does everyone seem to think this a black-and-white issue? You answered your own question. Inappropriate use of checked exceptions is built into the heart of the Java standard libraries, which means that (a) every new Java programmer is taught, consciously or subconsciously, to use them everywhere, at least until the programmer is very explicitly educated about their badness; (b) even experienced Java programmers must deal with them every day, and 95% of the checked exceptions they deal with are an unredeemed pain in the ass, so before long the very sight of one makes you flinch. It's Pavlovian. In a language community where checked exceptions were a completely optional add-on which was only used when appropriate, they might have a much better reputation.