Example usage for java.lang ExceptionInInitializerError getException

List of usage examples for java.lang ExceptionInInitializerError getException

Introduction

In this page you can find the example usage for java.lang ExceptionInInitializerError getException.

Prototype

public Throwable getException() 

Source Link

Document

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

Usage

From source file:eu.stratosphere.runtime.fs.hdfs.DistributedFileSystem.java

private org.apache.hadoop.fs.FileSystem instantiateFileSystem(
        Class<? extends org.apache.hadoop.fs.FileSystem> fsClass) throws IOException {
    try {//from w ww.  j  a  va  2s .c  o  m
        return fsClass.newInstance();
    } catch (ExceptionInInitializerError e) {
        throw new IOException(
                "The filesystem class '" + fsClass.getName() + "' throw an exception upon initialization.",
                e.getException());
    } catch (Throwable t) {
        String errorMessage = InstantiationUtil.checkForInstantiationError(fsClass);
        if (errorMessage != null) {
            throw new IOException(
                    "The filesystem class '" + fsClass.getName() + "' cannot be instantiated: " + errorMessage);
        } else {
            throw new IOException(
                    "An error occurred while instantiating the filesystem class '" + fsClass.getName() + "'.",
                    t);
        }
    }
}

From source file:org.apache.click.ClickServlet.java

/**
 * Handle the given servlet request and render the results to the
 * servlet response.//from   www  .  j  av  a 2  s  .  c o m
 * <p/>
 * If an exception occurs within this method the exception will be delegated
 * to:
 * <p/>
 * {@link #handleException(HttpServletRequest, HttpServletResponse, boolean, Throwable, Class)}
 *
 * @param request the servlet request to process
 * @param response the servlet response to render the results to
 * @param isPost determines whether the request is a POST
 * @throws IOException if resource request could not be served
 */
protected void handleRequest(HttpServletRequest request, HttpServletResponse response, boolean isPost)
        throws IOException {

    // Handle requests for click resources, i.e. CSS, JS and image files
    if (resourceService.isResourceRequest(request)) {
        resourceService.renderResource(request, response);
        return;
    }

    long startTime = System.currentTimeMillis();

    if (logger.isDebugEnabled()) {
        HtmlStringBuffer buffer = new HtmlStringBuffer(200);
        buffer.append(request.getMethod());
        if (ServletFileUpload.isMultipartContent(request)) {
            buffer.append(" (multipart) ");
        } else {
            buffer.append(" ");
        }
        buffer.append(request.getRequestURL());
        logger.debug(buffer);
    }

    // Handle click page requests
    Page page = null;
    try {

        ActionEventDispatcher eventDispatcher = createActionEventDispatcher();
        // Bind ActionEventDispatcher to current thread
        ActionEventDispatcher.pushThreadLocalDispatcher(eventDispatcher);

        ControlRegistry controlRegistry = createControlRegistry();
        // Bind ControlRegistry to current thread
        ControlRegistry.pushThreadLocalRegistry(controlRegistry);

        Context context = createContext(request, response, isPost);
        // Bind context to current thread
        Context.pushThreadLocalContext(context);

        // Check for fatal error that occurred while creating Context
        Throwable error = (Throwable) request.getAttribute(Context.CONTEXT_FATAL_ERROR);

        if (error != null) {
            // Process exception through Click's exception handler.
            if (error instanceof Exception) {
                throw (Exception) error;
            }
            // Errors are not handled by Click, let the server handle it
            if (error instanceof Error) {
                throw (Error) error;
            } else {
                // Throwables are not handled by Click, let the server handle it
                throw new RuntimeException(error);
            }
        }

        page = createPage(context);

        // If no page created, then an PageInterceptor has aborted processing
        if (page == null) {
            return;
        }

        if (page.isStateful()) {
            synchronized (page) {
                processPage(page);
                processPageOnDestroy(page, startTime);
                // Mark page as already destroyed for finally block
                page = null;
            }

        } else {
            processPage(page);
        }

    } catch (Exception e) {
        Class<? extends Page> pageClass = configService.getPageClass(ClickUtils.getResourcePath(request));

        handleException(request, response, isPost, e, pageClass);

    } catch (ExceptionInInitializerError eiie) {
        Throwable cause = eiie.getException();
        cause = (cause != null) ? cause : eiie;

        Class<? extends Page> pageClass = configService.getPageClass(ClickUtils.getResourcePath(request));

        handleException(request, response, isPost, cause, pageClass);

    } finally {

        try {
            if (page != null) {
                if (page.isStateful()) {
                    synchronized (page) {
                        processPageOnDestroy(page, startTime);
                    }

                } else {
                    processPageOnDestroy(page, startTime);
                }
            }

            for (PageInterceptor interceptor : getThreadLocalInterceptors()) {
                interceptor.postDestroy(page);
            }

            setThreadLocalInterceptors(null);

        } finally {
            // Only clear the context when running in normal mode.
            if (request.getAttribute(MOCK_MODE_ENABLED) == null) {
                Context.popThreadLocalContext();
            }
            ControlRegistry.popThreadLocalRegistry();
            ActionEventDispatcher.popThreadLocalDispatcher();
        }
    }
}

From source file:org.seasar.dwr.servlet.S2DwrServlet.java

public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    ServletContext servletContext = servletConfig.getServletContext();

    try {//  w  w w.  ja v a2  s.c o m
        // setupLogging() only needed for servlet logging if commons-logging
        // is unavailable
        // logStartup() just outputs some version numbers
        StartupUtil.setupLogging(servletConfig, this);
        StartupUtil.logStartup(servletConfig);

        // create and setup a DefaultContainer
        container = ContainerUtil.createDefaultContainer(servletConfig);
        // ContainerUtil.setupDefaultContainer(container, servletConfig);
        ContainerUtil.setupDefaults(container, servletConfig);
        container.addParameter(HtmlCallMarshaller.class.getName(), S2HtmlCallMarshaller.class.getName());
        container.addParameter(PlainCallMarshaller.class.getName(), S2PlainCallMarshaller.class.getName());
        ContainerUtil.setupFromServletConfig(container, servletConfig);
        container.setupFinished();

        webContextBuilder = StartupUtil.initWebContext(servletConfig, servletContext, container);
        StartupUtil.initServerContext(servletConfig, servletContext, container);

        ContainerUtil.prepareForWebContextFilter(servletContext, servletConfig, container, webContextBuilder,
                this);
        ContainerUtil.configureContainerFully(container, servletConfig);
        ContainerUtil.publishContainer(container, servletConfig);
    } catch (ExceptionInInitializerError ex) {
        log.fatal("ExceptionInInitializerError. Nested exception:", ex.getException());
        throw new ServletException(ex);
    } catch (Exception ex) {
        log.fatal("DwrServlet.init() failed", ex);
        throw new ServletException(ex);
    } finally {
        if (webContextBuilder != null) {
            webContextBuilder.unset();
        }

        ServletLoggingOutput.unsetExecutionContext();
    }
}