By bloid
via gafter.blogspot.com
Published: May 27 2007 / 17:51
There has been an ongoing debate on the utility of checked exceptions. Many people are critical of Java's checked exceptions, characterizing them as a failed experiment in software engineering. In practice, checked exceptions can result in API complexity, and programs appear to be cluttered with exception handling code just to satisfy the compiler. Some people believe checked exceptions are a good language feature but are misused, even in the JDK. With the "experts" being such poor role models, how can we expect ordinary Java programmers to do better?



Comments
murban replied ago:
Personally, I think checked exceptions are a good thing, and one of the reasons that Java is so well suited for mission critical applications. Of course, the problem is that programmers often defeat the purpose by simply catching the exceptions and ignoring them just to satisfy the compiler, instead of recovering from them in a graceful way. But this is not a defect in the concept of checked exceptions. Rather it is a failure on the part of developers to take advantage of the features of Java that allow them to write more reliable and fault tolerant software.
Mihai Campean replied ago:
I agree, we should not blame nor change a good thing because of our inability to understand and use it properly. I have been searching for best practices in exception handling for Java but I could not find a simple and useful way that can be generally applied. I guess this is one of those "no silver bullet" things, however we shouldn't give up hope on it just yet.
kunnar replied ago:
But most of the time there is nothing else to do with checked exception than wrap it to RuntimeException and throw it. I am not saying that checked exceptions are bad, but they are definately overused in Java. Here is good discussion about checked and unchecked exceptions: http://dev2dev.bea.com/pub/a/2006/11/effective-exceptions.html
georgi replied ago:
Checked exceptions are not overused in Java. I confess that I do like a programming language / core API that forces me to catch exceptions via compiler errors (where applicable) more than the .NET - stuff that does not even precisely explain when which exception may raise eventually in which condition (or not). Yes, I worked with that stuff to. And visiting your link and due to all respect for BEA, sentences like "An I/O failure is a serious but extremely rare event. On top of that, there is usually nothing your code can do to recover from one." - that is not beareable. An I/O failure may occur one in a million (heck, let's say one in a trillion), but the programmer has to be aware that it _might happen all the time_ . That's what checked exceptions are for, to understand my opinion look at the last chapter of: http://www.dzone.com/links/thoughts_on_successful_exception_handling.html
kunnar replied ago:
Looks like different people have different views on this. I can give another link for just showing that there are good programmers who are thinking that checked exceptions are overused in Java. For example Spring Framework people have written this right into there mission statement:
Checked exceptions are overused in Java. A framework shouldn't force you to catch exceptions you're unlikely to be able to recover from.
Link: http://www.springframework.org/about
tom.palmer.myopenid.com replied ago:
Don't mean to be a troll, but Java checked exceptions are just terrible. Everything is bad about them except in fairy tales. I've gone into more detail on other occasions. Just casting a quick vote here.
Voters For This Link (14)
Voters Against This Link (1)