aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt about ExceptionInInitializerError Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Doubt about ExceptionInInitializerError" Watch "Doubt about ExceptionInInitializerError" New topic
Author

Doubt about ExceptionInInitializerError

Aravind Jerubandi
Ranch Hand

Joined: Dec 17, 2006
Posts: 49
When i check the java doc 'ExceptionInInitializerError' extends 'Error'. But i'm able to catch it with 'Exception' class as shown below. When i replace 'Exception' with 'Error' in the below code it doesn't catch the exception/error!!!

Is 'ExceptionInInitializerError' an exception or an error? Someone please clarify.




[ October 25, 2008: Message edited by: Aravind Jerubandi ]

[ October 25, 2008: Message edited by: Aravind Jerubandi ]
[ October 25, 2008: Message edited by: Aravind Jerubandi ]

-Aravind<br />SCJP 5.0 (91%), Preparing for SCBCD.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

When I run your code I get an java.lang.ArithmeticException: / by zero.
Which is to be expected. I have never heard of an ExceptionInInitilizationError and I can't find anything about it. Can you give a link to the javadoc and/or source.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Aravind Jerubandi
Ranch Hand

Joined: Dec 17, 2006
Posts: 49
I'm extremely sorry. It is 'ExceptionInInitializerError'. It was a typo.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Aha. I thought it would be something like that.
I think your confused. By not catching the / by zero exception an error is raised by the JVM. By catching the exception no problems where found thus the jvm doesn't rais an error.

The / by 0 is an exception that causes an error, the ExceptionInInitializerError, to by raised by the jvm because it is in a static initialiser.
Aravind Jerubandi
Ranch Hand

Joined: Dec 17, 2006
Posts: 49
Thank you so much!!!

I got it. Don't know why it didn't strike to me...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32694
    
    4
campbell@linux-pgix:~/java> gedit InitialiserErrorDemo.java
campbell@linux-pgix:~/java> javac InitialiserErrorDemo.java
campbell@linux-pgix:~/java> java InitialiserErrorDemo
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.ArithmeticException: / by zero
at InitialiserErrorDemo.<clinit>(InitialiserErrorDemp.java:6)
Could not find the main class: InitialiserErrorDemo. Program will exit.
campbell@linux-pgix:~/java>
That is how you can convert your ArithmeticException to an ExceptionInInitializerError.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt about ExceptionInInitializerError
 
Similar Threads
Problem with Hibernate Cache
Generics question
Problem using Annotations in hibernate
Whats the Difference
Class Type Casting