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


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

value[slot] = data;

Checked Exceptions

Keep in mind that the Java virtual machine is executing 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).

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 following excerpt throws the exception to its caller:

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 ...

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.)


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