当前位置:编程学习 > JAVA >>

异常

为什么异常对象向堆栈打印异常信息的这一步每次执行的时间都不一样呢?

public class 异常2 {
public static void main(String[] args) {
try{
System.out.println("try语句块开始执行!");
int i=10,j=0;
System.out.println(i/j);
System.out.println("try语句块执行结束!");
}catch(ArithmeticException e){
System.out.println("catch语句块执行!");
e.printStackTrace();
System.out.println("***");
}finally{
System.out.println("finally语句块执行!");
}

System.out.println(compute());
}


public static int compute(){
try{
//myMethod();//无论此方法是否出现异常,compute()方法都返回3.
return 1;
}catch(Exception e){
return 2;
}finally{
return 3;
}
}
}

该程序运行不同次数后的结果是:异常信息有时出现的早有时出现在最后 --------------------编程问答-------------------- 这是由JVM决定的,与程序无关
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,