package com.cxx.exception;public class ExcptionTest { public void method() throws Exception{
System.out.println("thank you for your help");
throw new Exception();
}
public static void main(String[] args) {
ExcptionTest excptionTest=new ExcptionTest();
try {
excptionTest.method();
} catch (Exception e) { e.printStackTrace();
}
finally {
System.out.println("say thanks the end");
}
}
}
运行执行的结果是
thank you for your help
say thanks the end
java.lang.Exception
at com.cxx.exception.ExcptionTest.method(ExcptionTest.java:7)
at com.cxx.exception.ExcptionTest.main(ExcptionTest.java:13))
调试的结果却是
thank you for your help
java.lang.Exception
at com.cxx.exception.ExcptionTest.method(ExcptionTest.java:7)
at com.cxx.exception.ExcptionTest.main(ExcptionTest.java:13)
say thanks the end
异常处理是不是按顺序执行的?
求深入分析
System.out.println("thank you for your help");
throw new Exception();
}
public static void main(String[] args) {
ExcptionTest excptionTest=new ExcptionTest();
try {
excptionTest.method();
} catch (Exception e) { e.printStackTrace();
}
finally {
System.out.println("say thanks the end");
}
}
}
运行执行的结果是
thank you for your help
say thanks the end
java.lang.Exception
at com.cxx.exception.ExcptionTest.method(ExcptionTest.java:7)
at com.cxx.exception.ExcptionTest.main(ExcptionTest.java:13))
调试的结果却是
thank you for your help
java.lang.Exception
at com.cxx.exception.ExcptionTest.method(ExcptionTest.java:7)
at com.cxx.exception.ExcptionTest.main(ExcptionTest.java:13)
say thanks the end
异常处理是不是按顺序执行的?
求深入分析
at com.cxx.exception.ExcptionTest.method(ExcptionTest.java:7)
at com.cxx.exception.ExcptionTest.main(ExcptionTest.java:13)这部分是系统打印的后台信息吧调试的时候 ,应该是后台把异常信息打印出来,然后再把内容打印出来吧
thank you for your help
java.lang.Exception
say thanks the end
at com.cxx.exception.ExcptionTest.method(ExcptionTest.java:7)
at com.cxx.exception.ExcptionTest.main(ExcptionTest.java:13))
多线程的问题。如果真是楼主写的那样我就没法理解了。
情况又不一样了
第一,二次
thank you for your help
say thanks the end
java.lang.Exception
at com.cxx.exception.ExcptionTest.method(ExcptionTest.java:7)
at com.cxx.exception.ExcptionTest.main(ExcptionTest.java:13)
第三,四次
java.lang.Exception
at com.cxx.exception.ExcptionTest.method(ExcptionTest.java:7)
at com.cxx.exception.ExcptionTest.main(ExcptionTest.java:13)
thank you for your help
say thanks the end
e.printStackTrace(System.out);那么输出结果是确定的。
这样就统一了,你会看到异常执行的顺序
catch (Exception e) {
e.printStackTrace(System.out);
}
你可以看下源码e.printStackTrace,里面是做了同步处理的,但是默认调用的是System.err输出流。