package debug; public class MyTest{ static int i = 100/0; public static void main(String[] args){ Ssytem.out. } } 執行一下看看,這是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(); } } 然后進行反編譯: