Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Whats the best way to design a singleton class that could throw an exception? Here I have a Singleton (using Bill Pugh's method, documented in Wiki for Singleton). private static class SingletonObjectFactoryHolder{ //1 private static final ObjectFactory INSTANCE = new ObjectFactory(); } private ObjectFactory() throws Exception{ //2 //create the facto...
I have a plugin module that goes into a web application. If the module does not load correctly, it does not make sense for the web application to go on, and the web application should probably not load at all, we would prefer this module to initialize correctly always. If I were to throw a runtime exception, it would get into the logs, and just get ignored since the application will continue an...
I have a couple questions regarding using the entity manager in a JavaSE environment. I'm using the repository pattern to perform my CRUD operations on the database. There will be a base repository class like so: public class Repository<T> implements IRepository<T> { private EntityManager em; private String persistenceUnitName; public Repository(String persistenceUni...
I have a static setter that is used to set all instances of MyClass: public class MyClass { .... protected static final Setter setter = new Setter(); ... } However this does not compile since the setter constructor throws an exception: public class Setter { public Setter() throws FileNotFoundException { .... } } How can I work around this?
My objective is to have a private static Properties object in my class, to act as defaults when creating other Properties objects needed by my application. The current implementation looks like this: public class MyClass { private static Properties DEFAULT_PROPERTIES = new Properties(); static { try { DEFAULT_PROPERTIES.load( MyClass.class.getResource...
I need a database connection in Java Web service implemented as a session bean, and I'm not sure if I do it right. I created a class public final class SQLUtils { //..... private static DataSource m_ds=null; static { try { InitialContext ic = new InitialContext(); m_ds = (DataSource) ic.lookup(dbName); //Connection pool...
  /*
   * Copyright 1996-2000 Sun Microsystems, Inc.  All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Sun designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Sun in the LICENSE file that accompanied this code.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * version 2 for more details (a copy is included in the LICENSE file that
  * accompanied this code).
  *
  * You should have received a copy of the GNU General Public License version
  * 2 along with this work; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  * CA 95054 USA or visit www.sun.com if you need additional information or
  * have any questions.
  */
 
 package java.lang;

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."

Author(s):
Frank Yellin
Since:
JDK1.1
 
 public class ExceptionInInitializerError extends LinkageError {
    
Use serialVersionUID from JDK 1.1.X for interoperability
 
     private static final long serialVersionUID = 1521711792217232256L;

    
This field holds the exception if the ExceptionInInitializerError(Throwable thrown) constructor was used to instantiate the object

Serial:
 
     private Throwable exception;

    
Constructs an ExceptionInInitializerError with null as its detail message string and with no saved throwable object. A detail message is a String that describes this particular exception.
 
     public ExceptionInInitializerError() {
         initCause(null);  // Disallow subsequent initCause
     }

    
Constructs a new ExceptionInInitializerError class by saving a reference to the Throwable object thrown for later retrieval by the getException() method. The detail message string is set to null.

Parameters:
thrown The exception thrown
 
     public ExceptionInInitializerError(Throwable thrown) {
         initCause(null);  // Disallow subsequent initCause
         this. = thrown;
     }

    
Constructs an ExceptionInInitializerError with the specified detail message string. A detail message is a String that describes this particular exception. The detail message string is saved for later retrieval by the Throwable.getMessage() method. There is no saved throwable object.

Parameters:
s the detail message
 
     public ExceptionInInitializerError(String s) {
         super(s);
         initCause(null);  // Disallow subsequent initCause
     }

    
Returns the exception that occurred during a static initialization that caused this error to be created.

This method predates the general-purpose exception chaining facility. The Throwable.getCause() method is now the preferred means of obtaining this information.

Returns:
the saved throwable object of this ExceptionInInitializerError, or null if this ExceptionInInitializerError has no saved throwable object.
    public Throwable getException() {
        return ;
    }

    
Returns the cause of this error (the exception that occurred during a static initialization that caused this error to be created).

Returns:
the cause of this error or null if the cause is nonexistent or unknown.
Since:
1.4
    public Throwable getCause() {
        return ;
    }
New to GrepCode? Check out our FAQ X