Search code examples
javaexceptionclassloader

Pass over ExceptionInInitializerError


I have a static initialization block and from it is thrown an ExceptionInInitializerError Exception.
Is there any way to pass over this exception and to access the other fields and methods from this class? Thank you.


Solution

  • Put the call to initiate the class which contains the static block into try block and catch ExceptionInInitializerError. Like the following:

    try{
        ClassWithStaticBlock cb = new ClassWithStaticBlock();
    }
        catch(ExceptionInInitializerError ex){      
    }