The Java Program: Reraise.java

  1 // Reraise.java
  2 
  3 /*
  4    Use "java -Djava.compiler=NONE Trace" to see line
  5    numbers in stack trace.
  6 */
  7 
  8 import java.util.NoSuchElementException;
  9 import java.io.FileNotFoundException;
 10 
 11 public class Reraise {
 12 
 13    /* Main can throw:
 14       ArrayIndexOutOfBoundsException, NumberFormatException,
 15       NoSuchElementException, or FileNotFoundException
 16    */
 17 
 18    public static void main (String argv[]) throws Exception {
 19 
 20       try {
 21 
 22          switch (0) {
 23          case 0: throw new ArrayIndexOutOfBoundsException ("darn!");
 24          case 1: throw new NumberFormatException ("merde!");
 25          case 2: throw new NoSuchElementException ("Scheiße!");
 26          case 3: throw new FileNotFoundException ("mierda!");
 27          }
 28 
 29          // Not reached
 30 
 31       } catch (ArrayIndexOutOfBoundsException e) {
 32          e.printStackTrace (System.err);
 33          throw e;
 34 
 35       } catch (NumberFormatException e) {
 36          e.printStackTrace (System.err);
 37          throw e;
 38 
 39       } catch (NoSuchElementException e) {
 40          e.printStackTrace (System.err);
 41          throw e;
 42 
 43       } catch (FileNotFoundException e) {
 44          e.printStackTrace (System.err);
 45          throw e;
 46 
 47       }
 48    }
 49 }