• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

IO Exception?

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
     
    Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
    Free, earth friendly heat - from the CodeRanch trailboss
    https://www.kickstarter.com/projects/paulwheaton/free-heat
    reply
      Bookmark Topic Watch Topic
    • New Topic