Should Java IOException have been an unchecked RuntimeException?

Posted by Derek Mahar on Stack Overflow See other posts from Stack Overflow or by Derek Mahar
Published on 2010-04-12T17:51:37Z Indexed on 2010/04/12 17:52 UTC
Read the original article Hit count: 381

Do you agree that the designers of Java class java.io.IOException should have made it an unchecked run-time exception derived from java.lang.RuntimeException instead of a checked exception derived only from java.lang.Exception?

I think that class IOException should have been an unchecked exception because there is little that an application can do to resolve problems like file system errors. However, in When You Can't Throw An Exception, Elliotte Rusty Harold claims that most I/O errors are transient and so you can retry an I/O operation several times before giving up:

For instance, an IOComparator might not take an I/O error lying down, but — because many I/O problems are transient — you can retry a few times, as shown in Listing 7:

Is this generally the case? Can a Java application correct I/O errors or wait for the system to recover? If so, then it is reasonable for IOException to be checked, but if it is not the case, then IOException should be unchecked so that business logic can delegate handling this exception to a separate system error handler.

© Stack Overflow or respective owner

Related posts about java

Related posts about exception