您的位置:首页 > 其它

finally抛异常

2016-05-12 15:18 375 查看
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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: