What is a checked exception

Checked exceptions

Please do not forget that it is Java Bytecode that is being executed, not the Java source code. But the bytecode file contains information about which lines of the source code correspond to those of the bytecode. The other line numbers are not particularly useful to us as they refer to the method's source code (written by Sun Microsystems) which is not part of our file.

Some types of exception are checked exceptions, that means that a method has to do something with it. The compiler checked any method to be sure it does. There are two things a method can do with a checked exception:

  1. Catch the exception in a block or
  2. pass the exception to the caller of the method.

For example, one is a checked exception. So far, your programs have done something like this with it:

public class MachtIO {public static void main (String [] args) throws IOException {BufferedReader stdin = new BufferedReader (new InputStreamReader (System.in)); // more Java instructions ...}}

The reserved word means that this method does not catch them and that if one occurs in this method, it will be passed on to the method that called it. (In this example it is passed on to the Java runtime system.)


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