Back to notes -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    A Java program - does not compile.Lecture 9 - slide 27 : 30
Program 1
// Java
class Problem extends Exception{
  Problem(){super();}
  Problem(String s) {super(s);}
}

public class CatchOrSpecifyDemo0 {

  public static void main(String[] args){   
      explosion();      // Compile-time error:
                        //   unreported exception Problem;
                        //   must be caught or declared to be thrown
  }

  static void explosion() throws Problem {    
    System.out.println("Explosion!");
    throw new Problem("We have an explosive problem");
  }

}
 
 
 
 
 
 
 
 
Main fails to catch or specify Problem.
 
 
 
 
 
The method explosion specifies Problem.