go to previous page   go to home page   go to next page

Answer:

The first stacktrace shows the information available in the Exception object that was caught, which is just local informtion. The second stacktrace was generated by the run time system and shows the complete stack at the time of the exception.

The stack is a data structure that keeps information about methods as they are called.


Checked Exceptions


public class DoesIO
{
  public static void main ( String[] a ) throws IOException
  {
    BufferedReader stdin = 
        new BufferedReader ( new InputStreamReader( System.in ) );

    String inData;
    inData = stdin.readLine();
    
    // More Java statements ...
  }
}

Some exception types are checked exceptions, which means that a method must do something about them. The compiler checks to make sure that this is done. There are two things a method can do with a checked exception. It can:

  1. handle the exception in a catch{} block, or
  2. throw the exception to the caller of the method.

For example, an IOException is a checked exception. Some programs use the readLine() method of BufferedReader for input. This method throws an IOException when there is a problem reading. Programs that use BufferedReader for input need to do something about possible exceptions. The above code excerpt throws the exception to its caller.

The reserved word throws says that this method does not catch the IOException, and that when one occurs it will be thrown to its caller. (In this example, it will be thrown up to the Java runtime system.)


QUESTION 5:

(Thought question: ) What happens to the exception when it is thrown to the Java runtime system?


go to previous page   go to home page   go to next page