ExceptionInInitializerError would get my vote, to quote the doc:

Signals that an unexpected exception has occurred in a static
initializer. An ExceptionInInitializerError is thrown to indicate that
an exception occurred during evaluation of a static initializer or the
initializer for a static variable.

As of release 1.4, this exception has been retrofitted to conform to
the general purpose exception-chaining mechanism. The "saved throwable
object" that may be provided at construction time and accessed via the
getException() method is now known as the cause, and may be accessed
via the Throwable.getCause() method, as well as the aforementioned
"legacy method."


That said, using static blocks has a bit of a whiff to it..

Brian



On Thu, May 29, 2008 at 3:47 PM, Jeff Mutonho <[EMAIL PROTECTED]> wrote:
> What are the best practises when it comes to handling exceptions  in a
> static initializer. Say you have code that looks like :
>
> static {
>         try {
>             if (ServiceManager.service == null) {
>                 Context ctx = new InitialContext();
>                 //perform some lookup from JNDI
>             }
>         } catch (Exception e) {
>             log.log(Priority.ERROR,  "Exception"+ e.getMessage());
>
>         }
>     }
>
>
> lol.log is not good enough , as it doesn't make sense to proceed if
> something wrong happened with the lookup code in the try block.I've seen a
> few debates on the net and it seems some propose that after logging  in the
> catch block , then one should throw an ExceptionInInitializer as shown below
> :
>
> catch (Exception e) {
>             log.log(Priority.ERROR,  "Exception"+ e.getMessage());
>             throw new ExceptionInInitializerError(e);
>         }
>
> Other posts on the net go as far as saying one should throw RuntimeException
> or even use System.exit(1)
>
> What are your thoughts on this?  Any best practises that you could
> recommend?
>
>
>
>
>
>
> --
>
> "Don't take the name of root in vain."
>
> Jeff Mutonho
> Cape Town
> South Africa
>
> GoogleTalk : ejbengine
> Skype : ejbengine
> Registered Linux user number 366042
> >
>



-- 
Brian Silberbauer
Consultant

+27 (0)83 566 2705
skype: brian.silberbauer
http://www.linkedin.com/in/briansilberbauer

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CTJUG Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/CTJUG-Forum
For the ctjug home page see http://www.ctjug.org.za
-~----------~----~----~----~------~----~------~--~---

Reply via email to