File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes IO Exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "IO Exception?" Watch "IO Exception?" New topic

IO Exception?

Sally Curtis

Joined: Jan 10, 2004
Posts: 26
im confused about ioException....what exactly is it and in a method when it says Throws does it do that...what has to happen for it to do that?
i have a snippet of a code here
catch(IOException excpt)
well,how does it get into the catch statement?
Scott Solomko

Joined: Apr 11, 2004
Posts: 4
Here is the link to the Java API that explains IOException.
What exactly is it ... it is an Input/Output Exception, meaning some unexpected event regarding I/O happened. There are several events that can happen to cause this exception to be thrown
A method that declares it "throws IOException" is telling the caller that "if things don't go as planned in this method, I will notify you by throwing this exception".
The catch code you included in your post is part of the caller's source file, not the method that is declaring it throws IOException.
Hope that helps,

It is the soldier who salutes the flag, who serves beneath the flag, and whose coffin is draped by the flag, who allows the protester to burn the flag.
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
First of all, while you may view the classes in the package as system code, the operating system views them as application code, mostly written in Java. So when one of the methods in detects an error (often based on the return code from a call to the operating system, based in turn on an electronic signal from a physical IO device such as a disk drive), it will execute
just as you could do.
Once the exception is thrown, the JVM checks for a corresponding catch block in the current code. If none is there, the JVM "pops the stack" and checks if the calling program has a catch block for this exception. Once a catch block for is found, any lower level method invocations are dropped and the catch block is called with the IOException object, containing information about the error, passed as an argument. If even the "main" method doesn't catch the exception, the JVM terminates the program and displays some information on the screen.

Mike Gershman
SCJP 1.4, SCWCD in process
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
You might like to read Chapters 80 and 81 of Bradley Kjell's Introduction to Computer Science using Java for a good introduction to the subject.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
And I just ran across my list of resources on learning Exception handling.
If you have some free time, to learn the basics of exception handling, I recommend reading
  • chapter 9 of Bruce Eckel's Thinking In Java Book
  • chapter 9 of David J. Eck's Introduction to Programming Using Java
  • chapters 80 & 81 of Bradley Kjell's Introduction to Computer Science using Java
  • Dick Baldwin's The Essence of OOP using Java, Exception Handling Article and
  • The Handling Errors with Exceptions Lesson of Sun's Java Tutorial
  • Then, when you're ready to have some fun, take a look at this past JavaRanch conversation as well as
    I agree. Here's the link:
    subject: IO Exception?
    It's not a secret anymore!