Undocumented Changes in Java 6 Mustang: IOError

At some point, a new java.io.IOError class was added to Java 6. This is “Thrown when a serious I/O error has occurred.” No further explanation is offered.

This is not listed as a change in the JDK 6 documentation; and I haven’t noticed this addition in any JSRs, though I could easily have missed one. Can anyone explain where this new class has come from and what is likely to cause it be thrown?

After grepping through the source, it appears that this is used in exactly one class, java.io.Console; and there it’s used purely to hide an IOException. i.e. the code looks like this:

try {
  //... something that might throw an IOException
}
catch (IOException ex) {
  throw new IOError(ex);
}

This is wrong. There’s nothing here that’s so bad it justifies throwing an Error and shutting down the VM. There is nothing here that a reasonably written program could not plausibly recover from. The methods declared to throw IOError should be declared to throw IOException instead.

It’s possible that reasonably functioning program should never throw this error. In that case, this is the proper response:

try {
  //... something that really shouldn't throw an IOException
}
catch (IOException ex) {
  throw new RuntimeException(ex, "This shouldn't happen");
}

There’s no reason to introduce a new class and throw an error here. If it’s possible the exception might actually happen, and Sun doesn’t want to do the right thing and declare that each one throws IOException, and Sun does want something a little more descriptive than athen they should define a new IORuntimeException instead. Errors should be reserved for truly nasty, unrecoverable conditions like stack overflows and running out of memory. I/O errors don’t qualfiy.

Oh, and if anyone at Sun is reading this can you please fix the comments’ email address on
http://download.java.net/jdk6/docs/guide/io/index.html? Mail sent to io@java.sun.com is bouncing.

4 Responses to “Undocumented Changes in Java 6 Mustang: IOError”

  1. Mark Reinhold Says:

    The new IOError class was defined in combination with the
    new java.io.Console class. It’s for use in situations where
    an unrecoverable I/O error occurs and the most appropriate
    response is to terminate the program rather than attempt to
    handle the exception.

    The IOError class, along with many other enhancements, will
    be documented in the forthcoming Mustang maintenance review
    in the JCP.

  2. Elliotte Rusty Harold Says:

    What would such a situation be? What methods might throw this error?

  3. Texas Hold Em Tournament Rule Says:

    Texas Hold Em Tournament Rule

    portend?armpits milliwatt rangeland

  4. Dr Aaron Kans Says:

    IOError seems to be an unchecked excpetion, whereas IOException was checked.

    Is this why it was developed? To change from a rigorous checked excpetion to a looser unchecked exception for IO errors? If so is this not a dangerous thing to do? Surely all IO errors chould be checked?

Leave a Reply