finally里面抛异常,话不多说,上代码和结果;
public class FinallyExcepTest { private static void test01(int a){ try { System.out.println("hello"); }finally { System.out.println("1--"); int b = 1/a; System.out.println(b); System.out.println("2--"); } } public static void main(String[] args){ test01(0); }}
hello 1-- Exception in thread "main" java.lang.ArithmeticException: / by zero at me.base.knowledge.exception.FinallyExcepTest.test01(FinallyExcepTest.java:18) at me.base.knowledge.exception.FinallyExcepTest.main(FinallyExcepTest.java:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)