Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When might an IOError be thrown?

Tags:

java

ioerror

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 IOException -- IOException is thrown in a wide range of cases, and is commonly used; I know that. I'm wondering about the less common IOError).

like image 385
Pokechu22 Avatar asked Mar 23 '15 02:03

Pokechu22


People also ask

What is an IOError?

It is an error raised when an input/output operation fails, such as the print statement or the open() function when trying to open a file that does not exist. It is also raised for operating system-related errors.

How do I get IOError?

Commonly, the IOError is raised when an input output operation like open() file, or a method or a simple print statement is failed due to IO reasons like “Disk full” or “File not found”. The IOError class is inherited from the EnvironmentError.

Which method will throw an IOException?

The Machine class has a public method called run(). This method declares that it throws an IOException. IOException (input-output exception) is part of the Java standard library.

What happens when exception is thrown?

When an exception is thrown using the throw keyword, the flow of execution of the program is stopped and the control is transferred to the nearest enclosing try-catch block that matches the type of exception thrown. If no such match is found, the default exception handler terminates the program.


1 Answers

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.

like image 175
Makoto Avatar answered Oct 05 '22 23:10

Makoto