ExceptionInInitializerError 오류를 처리하고 다시 초기화를 시키도록 시도하더라도 정상적으로 동작하지 않을 것이다
public class Main {
public static void main (String [] args) throws Exception {
for (int repeat = 0; repeat < 3; ++ repeat) {
try {
// "Real" name for X is outer class name+$+nested class name:
Class.forName ("Main$X");
} catch (Throwable t) {
System.out.println ("load attempt #" + repeat + ":");
t.printStackTrace (System.out);
}
}
}
private static class X {
static {
if (++ s_count == 1)
throw new RuntimeException ("failing static initializer...");
}
} // End of nested class
private static int s_count;
} // End of class
X의 static initializer는 모두 실패처리가 되었다
>java Main
load attempt #0:
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
at Main.main(Main.java:17)
Caused by: java.lang.RuntimeException: failing static initializer...
at Main$X.(Main.java:40)
... 3 more
load attempt #1:
java.lang.NoClassDefFoundError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
at Main.main(Main.java:17)
load attempt #2:
java.lang.NoClassDefFoundError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
at Main.main(Main.java:17)