• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt about ExceptionInInitializerError

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Aarav Thomas
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm extremely sorry. It is 'ExceptionInInitializerError'. It was a typo.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Aarav Thomas
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much!!!

I got it. Don't know why it didn't strike to me...
 
Marshal
Posts: 79044
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic