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 of this exception to a separate system error handler.