Checked Exceptions Are Wrong

Please note that this opinion is mine (and others as listed in the articles). This is not an edict that all code at YouDevise should be written without throws clauses. Just some food for thought.

So, it has been a bit mellow on the blog lately. I want to liven it up with a bit of a heated (nerdy) topic. Feel free to debate and discuss this in the comments.

A lot of people smarter than me have commented on whether Checked Exceptions are useful, so I am going to mostly link to their arguments. Do read the linked artickes. They are very insightful.

Here are my favorite points:

Checked exceptions are syntactic salt. The extra try/catch hoops that you have to jump through tend to make code less expressive and noisy.

Checked exceptions are hard to do right.
Often, they are so hard to do right that the Java language designers and other Java pundits cannot agree on any good practices for using them. Heck, people are seriously considering petitioning to remove the from the Java language.

Checked exceptions are a (failed) experiment. Java is the “first” language that used checked exceptions. Languages have been designed since then without checked exceptions. In fact, I cannot name a single major language since Java that has them… (Please correct me if I am wrong on that last point.)

My personal opinion? They rarely make my code more expressive, so the extra syntax and lines of code get in the way. As of late, nearly every Exception that I come across just means that the database threw an exception. These exceptions are almost always not recoverable, except at the highest layers of code, where you report an error status or other message to a user.

Anywho. What are y’all’s thoughts?