Results 1 to 4 of 4
  1. #1
    aytidaalkuhs is offline Member
    Join Date
    Apr 2008
    Posts
    3
    Rep Power
    0

    Default Where does the exception go?

    I was doing some file handling recently and used the read() method of the FileInputStream class. The read() method throws an IOException. I came across code (and used it as well) that looks like the snippet below.
    Java Code:
    class fileRead{
    public static void main(String []a) throws IOException {
    //do file handling here and call read as well
    }
    }

    Now, what i want to know is that who handles the IOException? Is it the JVM? If yes, how does it do it. If no, please help.

    waiting...
    aytidaalkuhs

  2. #2
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    9

    Default

    You are just throwing it. That means nobody handles it.

    If you write the code like this. You can handle it yourself:

    Java Code:
    class fileRead{
    public static void main(String []a) {
    
      try {
        //do file handling here and call read as well
      } catch(IOException e) {
    
        // handle your exception here
        e.printStackTrace();
    
      }
    }
    }

  3. #3
    DonCash's Avatar
    DonCash is offline Moderator
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    240
    Rep Power
    9

    Default

    Hey.

    Read this Sun Java Tutorial on Exceptions. Its very informative:

    Lesson: Exceptions (The Java™ Tutorials > Essential Classes)
    Did this post help you? Please me! :cool:

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Yes, it's. What is the best thing is handling the Exceptions. Normally what I have done is, catch all exceptions and put it into a log. So anytime latter I can check my error.

Similar Threads

  1. Need help on Exception
    By Deon in forum New To Java
    Replies: 7
    Last Post: 02-11-2010, 06:46 PM
  2. exception
    By Oktam in forum New To Java
    Replies: 2
    Last Post: 03-23-2008, 08:01 PM
  3. Replies: 1
    Last Post: 03-08-2008, 07:41 PM
  4. JSP Exception Hanling
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-24-2007, 10:57 AM
  5. Exception
    By Camden in forum New To Java
    Replies: 2
    Last Post: 11-27-2007, 12:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •