1 public class initexc 2 { 3 public static class fail 4 { 5 static 6 { 7 // Static initializers must be able to complete normally. 8 if (true) 9 throw new NullPointerException("nope"); 10 } 11 val()12 public static int val () 13 { 14 return 23; 15 } 16 } 17 main(String[] args)18 public static void main (String[] args) 19 { 20 try 21 { 22 System.out.println (fail.val ()); 23 } 24 catch (ExceptionInInitializerError _) 25 { 26 // Ok. 27 } 28 try 29 { 30 System.out.println (fail.val ()); 31 } 32 catch (NoClassDefFoundError _) 33 { 34 // Ok. 35 } 36 } 37 } 38