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

Answer:

It is the line number in the program where the exception occurred. That is the number of this line:

value[slot] = data;

The Java virtual machine executes Java bytecodes, not Java source code. However, the bytecode file contains information about how lines of source code and bytecodes correspond. Bytecodes from the Java libraries do not contain line numbers, which is why some of the lines of the stack trace say (Unknown Source).


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?