Demonstrate throw. : throw « Statement Control « Java Tutorial






class ThrowDemo {
  static void demoproc() {
    try {
      throw new NullPointerException("demo");
    } catch (NullPointerException e) {
      System.out.println("Caught inside demoproc.");
      throw e; // rethrow the exception
    }
  }

  public static void main(String args[]) {
    try {
      demoproc();
    } catch (NullPointerException e) {
      System.out.println("Recaught: " + e);
    }
  }
}








4.11.throw
4.11.1.Demonstrate throw.
4.11.2.Change Exception type and rethrow