Java Exception throw exception in catch block (rethrow)

Description

Java Exception throw exception in catch block (rethrow)

public class Main {
  void f() throws Exception {
    try {//from   w w w .  j av  a  2s .  co m
      throw new Exception();
    } catch (Exception e) {
      System.out.println("Handled paritally in f ()");
      throw e;
    }
  }

  void g() {
    try {
      f();
    } catch (Exception e) {
      System.out.println("Handled completely in g()");
    }
  }

  public static void main(String[] args) {
    new Main().g();
  }
}



PreviousNext

Related