KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > lang > ExceptionInInitializerError

java.lang
Class ExceptionInInitializerError

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Error
          extended by java.lang.LinkageError
              extended by java.lang.ExceptionInInitializerError
All Implemented Interfaces:
Serializable
See Also:
Top Examples, Source Code, Throwable.getCause(), getException()

public ExceptionInInitializerError()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1733]ExceptionInInitializerError()
By joe on 2006/03/20 19:27:43  Rate
I am working on Applet programming, inwhich, I am using CMLWriter method to convert a molecule object to CML ( Chemical Markup Language )  tags. CMLWriter method serializes a SetOfMolecules or a Molecule object to CML 2 code.  
        StringWriter output = new StringWriter (  ) ;  
        CMLWriter cmlwriter = new CMLWriter ( output ) ;  
        try  {        
        cmlwriter.write ( molecule ) ; //molecule is Molecule object. 
        cmlwriter.close (  ) ;  
        }  
       catch ( Exception e )   {  System.out.println ( e ) ;  }  
        String cmlcode = output.toString (  ) ; 
 I am able to capture molecule object. but, when i m going to convert it to cml tags, it gives me error: 
 java.lang.ExceptionInInitializerError 
     at org.openscience.cdk.libio.cml.Convertor.cdkAtomContainerToCMLMolecule ( Convertor.java:184 )  
     at org.openscience.cdk.libio.cml.Convertor.cdkMoleculeToCMLMolecule ( Convertor.java :180 )  
     at org.openscience.cdk.io.CMLWriter.write ( CMLWriter.java:173 )   ... 10 more 
 and  
 Caused by: java.security.AccessControlException: access denied  ( java.util.logging.LoggingPermission control )  
     at java.security.AccessControlContext.checkPermission ( Unknown Source )  
     at java.security.AccessController.checkPermission ( Unknown Source )  
     at java.lang.SecurityManager.checkPermission ( Unknown Source )   
     at java.util.logging.LogManager.checkAccess ( Unknown Source )  
     at java.util.logging.Logger.setLevel ( Unknown Source )  
     at org.xmlcml.cml.element.CMLMolecule. < clinit >  ( Unknown Source )  
     ... 19 more  
 


public ExceptionInInitializerError(String s)
See Also:
Throwable.getMessage()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1882]How to handle excepetion a Static Initializer Block
By Anonymous on 2007/05/25 12:58:10  Rate
In a class, you can create a static initializer block; this block is executed by the loader of this class exactly once, on initialization when the class is loaded. If a problem occurs, any Exception or Error is wrapped and thrown out of the static block  ( that???s why you catch Throwable ) . The wrapping in ExceptionInInitializerError is mandatory for static initializers. 
  
  
  
 public class SessionUtil  {  
  
  
 private static SessionFactory sessionFactory; 
  
  
   static  {  
     try  {  
       sessionFactory=new Configuration (  ) .configure (  ) .buildSessionFactory (  ) ; 
      }  catch  ( Throwable ex )   {  
       throw new ExceptionInInitializerError ( ex ) ; 
      }  
    }  
  } 


[1945]How To Handle Exceptions From Static Code Block in Java
By Anonymous on 2007/12/07 13:47:45  Rate
There are alternatives: 
  
  
 1. You can either throw a RuntimeException which will end the current thread  ( unless caught by code instantiating / calling a static method on the class for the first time )   
  
  
 2. or better yet you can call System.exit ( 1 ) . RuntimeException will end a single threaded application [ Laszlo ]   ( exception noted above ) . In JDK 1.5 throwing RuntimeException from main thread gives a pretty descriptive message: 
  
  
 Caused by: java.lang.RuntimeException: Error! 
 at TestStaticException. ( TestStaticException.java:3 )  
  
  
 At this point it may be argued that System.exit ( 1 )  is not desirable in a managed environment like a servlet and I agree. System.exit is for java applications and only if the static initializer block performs some critical  ( without which the program cannot be run successfully )  function like loading the database driver. RuntimeException may be consumed in a managed environment.  
  
  
 3. So a third option is to set a flag indicating failure. Later the constructors can check the flag and throw exceptions  [ Robert ]  or retry in rare cases.


public ExceptionInInitializerError(Throwable thrown)
See Also:
getException()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Throwable getCause()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Throwable getException()
See Also:
Throwable.getCause()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void printStackTrace()
See Also:
System.err, Throwable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void printStackTrace(PrintStream ps)
See Also:
Throwable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void printStackTrace(PrintWriter pw)
See Also:
Throwable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags