This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 61

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: 61
HI Lee Kian Giap ,

I Understood this one.

Thank you very much.
I agree. Here's the link:
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