This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes How to handle ExceptionInInitializerError ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to handle ExceptionInInitializerError ?" Watch "How to handle ExceptionInInitializerError ?" New topic

How to handle ExceptionInInitializerError ?

jami siva
Ranch Hand

Joined: Oct 16, 2009
Posts: 60

Below is my code, in this iam unable to catch ExceptionInInitializerError, iam only to catch NullPointerException Only,
Can any one make edjustments to this code to handle ExceptionInInitializerError.
Lee Kian Giap
Ranch Hand

Joined: Jan 23, 2008
Posts: 213
I think you can't because ExceptionInInitializerError is a chaining exception.

maybe you can try to use
NullPointerException.getCause() to return a Throwable object and cast it to ExceptionInInitializerError

or a better approach is

jami siva
Ranch Hand

Joined: Oct 16, 2009
Posts: 60
HI Lee Kian Giap ,

I Understood this one.

Thank you very much.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: How to handle ExceptionInInitializerError ?
Similar Threads
how to initialize static final field that the constructor throws some exception
Why not "Unreachable Code" Error..?
JVM vs Programmatically Exception
a question about exception