Example usage for java.lang InstantiationError initCause

List of usage examples for java.lang InstantiationError initCause

Introduction

In this page you can find the example usage for java.lang InstantiationError initCause.

Prototype

public synchronized Throwable initCause(Throwable cause) 

Source Link

Document

Initializes the cause of this throwable to the specified value.

Usage

From source file:hudson.lifecycle.Lifecycle.java

/**
 * Gets the singleton instance./*from  w  w w  .  j a v  a 2  s  .  com*/
 *
 * @return never null
 */
public synchronized static Lifecycle get() {
    if (INSTANCE == null) {
        String p = System.getProperty("hudson.lifecycle");
        if (p != null) {
            try {
                ClassLoader cl = Hudson.getInstance().getPluginManager().uberClassLoader;
                INSTANCE = (Lifecycle) cl.loadClass(p).newInstance();
            } catch (InstantiationException e) {
                InstantiationError x = new InstantiationError(e.getMessage());
                x.initCause(e);
                throw x;
            } catch (IllegalAccessException e) {
                IllegalAccessError x = new IllegalAccessError(e.getMessage());
                x.initCause(e);
                throw x;
            } catch (ClassNotFoundException e) {
                NoClassDefFoundError x = new NoClassDefFoundError(e.getMessage());
                x.initCause(e);
                throw x;
            }
        } else {
            // if run on Unix, we can do restart 
            if (!Hudson.isWindows()) {
                try {
                    INSTANCE = new UnixLifecycle();
                } catch (IOException e) {
                    LOGGER.log(Level.WARNING, "Failed to install embedded lifecycle implementation", e);
                }
            }

            // use the default one. final fallback.
            if (INSTANCE == null)
                INSTANCE = new Lifecycle() {
                };
        }
    }

    return INSTANCE;
}