public void handleException()

in ti/phase2/jars/core/src/java/org/apache/ti/pageflow/internal/DefaultExceptionsHandler.java [55:147]


    public void handleException(Throwable ex)
            throws PageFlowException {
        PageFlowActionContext actionContext = PageFlowActionContext.get();
        FlowController flowController = actionContext.getFlowController();

        if (_log.isInfoEnabled()) {
            _log.info("Handling Throwable " + ex.getClass().getName());
        }
        
        //
        // If we're already in the process of handling an exception, bail out.
        //
        Throwable alreadyBeingHandled = actionContext.getExceptionBeingHandled();

        if (alreadyBeingHandled != null) {
            if (_log.isWarnEnabled()) {
                _log.warn("Already in the process of handling " + alreadyBeingHandled.getClass().getName()
                        + "; bailing out of handling for " + ex.getClass().getName());
            }

            throw new UnhandledException(ex);
        }

        actionContext.setExceptionBeingHandled(ex);
        
        
        // Callback to the event reporter.
        AdapterManager.getContainerAdapter().getEventReporter().exceptionRaised(ex, flowController);
        long startTime = System.currentTimeMillis();
    
        //
        // Look up the ExceptionConfig that's associated with this Throwable.
        //
        Class exClass = ex.getClass();
        PageFlowAction action = actionContext.getAction();

        String exceptionHandlerName;
        if (action != null) {
            exceptionHandlerName = action.findExceptionHandler(exClass);
        } else {
            // If the mapping was null (i.e., the exception happened before we got the action mapping), look for the
            // exception only in the module config.
            exceptionHandlerName = flowController.getModuleConfig().findExceptionHandler(exClass);
        }
        
        //
        // If there was no applicable exception handler in the current ModuleConfig, look in Global.app's module.
        //
        if (exceptionHandlerName == null) {
            FlowController fallbackFC = getFallbackFlowController(flowController, exClass);

            if (fallbackFC != null) {
                flowController = fallbackFC;
                exceptionHandlerName = flowController.getModuleConfig().findExceptionHandler(exClass);

                if (exceptionHandlerName != null) {
                    // This is the module that will be handling the exception.  Ensure that its message resources are
                    // initialized.
                    InternalUtils.selectModule(flowController.getModuleConfig());
                    actionContext.setCurrentFlowController(flowController);
                }
            }
        }

        if (exceptionHandlerName != null) {
            if (_log.isDebugEnabled()) {
                _log.debug("Found exception-config for exception " + exClass.getName()
                        + ": handler=" + exceptionHandlerName);
            }

            //
            // First, see if it should be handled by invoking a handler method.
            //
            invokeExceptionHandler(exceptionHandlerName);

            // Callback to the event reporter.
            long timeTaken = System.currentTimeMillis() - startTime;
            Forward fwd = actionContext.getForward();
            AdapterManager.getContainerAdapter().getEventReporter().exceptionHandled(ex, flowController, fwd, timeTaken);
            return;
        }

        if (_log.isErrorEnabled()) {
            InternalStringBuilder msg = new InternalStringBuilder("Throwable ").append(exClass.getName());
            _log.error(msg.append(" unhandled by the current page flow (and any shared flow)").toString(), ex);
        }

        if (!getRegisteredExceptionsHandler().eatUnhandledException(ex)) {
            // Throwing this ServletException derivative will prevent any outer try/catch blocks from re-processing
            // the exception.
            throw new UnhandledException(ex);
        }
    }