package debug; public class MyTest{ static int i = 100/0; public static void main(String[] args){ Ssytem.out.PRintln("Hello,World!"); } } 执行一下看看,这是jdk1.5的输出:
java.lang.ExceptionInInitializerError Caused by: java.lang.ArithmeticException: / by zero at debug.MyTest.(Test.java:3) Exception in thread "main" 请注重,和其它方法调用时产生的异常一样,异常被定位于debug.MyTest的.
再来看:
package debug; public class Test { Test(){ int i = 100 / 0; } public static void main(String[] args) { new Test(); } } jdk1.5输入:
Exception in thread "main" java.lang.ArithmeticException: / by zero
package debug; public class Test { static int x = 0; static String s = "123"; static { String s1 = "456"; if(1==1) throw new RuntimeException(); } public static void main(String[] args) { new Test(); } } 然后进行反编译: