package MyTest.mytest;
public class Test02 {
public static void main(String[] args) {
try {
method();
} catch (NullPointerException e) {
System.out.print("G");
} catch (Exception e) {
System.out.print("A");
} finally {
System.out.print("B");
}
}
static void method() {
try {
wrench();
System.out.print("C");
} catch (ArithmeticException e) {
System.out.print("D");
} finally {
System.out.print("E");
}
System.out.print("F");
}
static void wrench() {
throw new NullPointerException();
}
}
1.调用method
2.调用wrench,抛出空指针,当前的try catch并不能处理NullPoint异常,因此走finally,并且抛出给method调用方,打印E
3.catch NullPoint ,打印G,finally 打印B
finally里面的输出语句一定会执行,不管有没有异常