Back to slide -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Annotated program -- Keyboard shortcut: 't'    exception/java-comparison/CatchOrSpecifyDemo1.java - A Java program - main handles Problem.Lecture 9 - slide 27 : 30
Program 2

// Java
class Problem extends Exception{
  Problem(){super();}
  Problem(String s) {super(s);}
}

public class CatchOrSpecifyDemo1 {

  public static void main(String[] args){     
    try {
      explosion();
    }
    catch (Problem e) {
      System.out.println("We handled the problem!");
      System.out.println("Or did we?");
    }  // try
  }

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

}