Skip to content
Advertisement

When might an IOError be thrown?

I have never seen a case when an IOError is thrown. The only thing that the docs say about IOError it this:

Thrown when a serious I/O error has occurred.

There aren’t any subclasses or anything else obvious.

Is there ever a case when IOError would be thrown in java? What might cause it?

(This is not to be confused with IOExceptionIOException is thrown in a wide range of cases, and is commonly used; I know that. I’m wondering about the less common IOError).

Advertisement

Answer

Console, Path#toAbsolutePath, and Path#toUri declare this particular exception to be thrown. Of course, that’s a documentation fact and not an actual declaration; since Error is a runtime exception, declaring it to be thrown in the signature would have no meaning.

From what it looks like in code, Console#readLine and Console#readPassword catch an IOException that results through its normal operation, then propagate that to an IOError.

Essentially, IOError represents a critical failing of the underlying filesystem, or accessing some resource that ties Java to the file system. It’s not thrown often, but it has the potential to be thrown if something serious happens from within the file system.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement