CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 1999
    Posts
    7

    Exception Handling

    I have written following code. When i compile it , it gives the error message

    import java.lang.*;
    import java.io.*;
    import java.util.*;

    public class Short
    {
    public static void main(String args[])
    {
    System.in.read();
    }

    }

    Error message

    Excpetion java.io.IOException must be caught




  2. #2
    Join Date
    Sep 1999
    Location
    Mainz, Germany
    Posts
    20

    Re: Exception Handling

    You must write the main like that:

    public static void main(String args[])
    {
    try
    {
    System.in.read();
    }
    catch (IOException e)
    {
    }
    }


  3. #3
    Join Date
    Sep 1999
    Posts
    7

    Re: Exception Handling

    Thanks Erbeere

    I have a question for you
    If any function declares as it throws exception
    and when we use it in any code block ,
    is it necessary that code block should be in
    try {}





  4. #4
    Join Date
    Sep 1999
    Location
    Mainz, Germany
    Posts
    20

    Re: Exception Handling

    Yes
    If a method throws an exception than you must set it in a try block and directly after that a catch block.
    If a method throws more exceptions than one, you only set one try but more catch blocks.
    For the beginning and if you speak German than it is the easiest if you will search for the Book "Java in 21 Tagen" there is everything explained really good but I don´t know if you´ll find this in English or another language


Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured