jQuery in Action, 2nd edition*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "IO Exception?" Watch "IO Exception?" New topic
Author

IO Exception?

Sally Curtis
Greenhorn

Joined: Jan 10, 2004
Posts: 26
Hi,
im confused about ioException....what exactly is it and in a method when it says Throws IOException....how 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
Greenhorn

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,
Scott


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 java.io package as system code, the operating system views them as application code, mostly written in Java. So when one of the methods in java.io 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 java.io.IOException 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
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Sally,
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
Sheriff

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 http://c2.com/cgi/wiki?IlluminateTheMainline
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: IO Exception?
     
    Similar Threads
    Tailing a file
    Simple input statement
    Something wrong with this input statement
    write a int to a file
    error handling