repository.grepcode.com$java$root@jdk$openjdk@6-b14
repository.grepcode.com$java$root@jdk$openjdk@6-b14@java$lang$ExceptionInInitializerError.java
file
oh
o
[]
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...
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
Use serialVersionUID from JDK 1.1.X for interoperability
This field holds the exception if the
ExceptionInInitializerError(Throwable thrown) constructor was
used to instantiate the object
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.
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
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
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.
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