empire-db-examples/empire-db-example-jsf2/src/main/java/org/apache/empire/jsf2/websample/web/AppExceptionHandler.java [63:168]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    public void handle()
        throws FacesException
    {
        // boolean redirectToErrorPage = false;
        Throwable rootCause = null;
        Iterator<ExceptionQueuedEvent> events = getUnhandledExceptionQueuedEvents().iterator();

        // log each error
        while (events.hasNext())
        {
            ExceptionQueuedEvent event = events.next();
            // handle
            try {
            
                ExceptionQueuedEventContext source = (ExceptionQueuedEventContext) event.getSource();
                FacesContext context = source.getContext();
                Throwable t = source.getException();
                
                // check t
                if (t==null)
                {   log.error("Cannot handle exception. Exception not supplied with context!");
                    setErrorMessage(context, null);
                    continue;
                }    

                // find root
                rootCause = t.getCause();
                // second option: getRootCause
                if (rootCause == null)
                {   // get cause
                    rootCause = getRootCause(t);
                }
                // third option: use t
                if (rootCause == null)
                {
                    rootCause = t;
                }
                
                // Walk up the tree
                while (true)
                {   // if its an empire-exception: game over
                    if (rootCause instanceof EmpireException)
                        break;
                    // has root cause
                    t = rootCause.getCause();
                    if (t==null)
                        break; 
                    // yes, continue search
                    rootCause = t;
                }
                
                /*
                if (rootCause instanceof org.icefaces.application.SessionExpiredException)
                {   // expired
                    log.info("Handling SessionExpiredException. No error message is set.");
                    continue;
                }
                */

                // set message
                String msg = "Handling exception of type "+rootCause.getClass().getSimpleName();
                // log
                // msg = appendSessionInfo(context, msg);
                log.error(msg, rootCause);
                
                // set message
                if (!(rootCause instanceof EmpireException))
                {   // Wrap as internal exception
                    rootCause = new InternalException(rootCause);
                }
                setErrorMessage(context, rootCause);
                
            } catch(Throwable t2) {
                log.error("Failed to handle exception: "+t2.getMessage(), t2);
            } finally {
                events.remove();
            }
        }

        // if an error has been found
        /*
        if (redirectToErrorPage)
        {
            HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
            try
            {
                // put error to session map (will be cleared by ErrorPage)
                if (rootCause != null)
                {
                    FacesUtils.getFin2Session().setError(rootCause);
                }
                // redirect to error page
                String errorPage = FacesUtils.getContextPath() + "/pages/error.iface";
                Fin2ExceptionHandler.log.debug("Redirecting to error page at '" + errorPage + "'...");
                FacesUtils.redirectDirectly(errorPage);
            }
            catch (Exception e)
            {
                Fin2ExceptionHandler.log.error("Error during exception handling.", e);
                throw new FacesException(e);
            }
        }
        */
        // let next handler deal
        getWrapped().handle();
    }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



empire-db-examples/empire-db-example-jakarta-faces/src/main/java/org/apache/empire/jakarta/websample/web/AppExceptionHandler.java [63:168]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    public void handle()
        throws FacesException
    {
        // boolean redirectToErrorPage = false;
        Throwable rootCause = null;
        Iterator<ExceptionQueuedEvent> events = getUnhandledExceptionQueuedEvents().iterator();

        // log each error
        while (events.hasNext())
        {
            ExceptionQueuedEvent event = events.next();
            // handle
            try {
            
                ExceptionQueuedEventContext source = (ExceptionQueuedEventContext) event.getSource();
                FacesContext context = source.getContext();
                Throwable t = source.getException();
                
                // check t
                if (t==null)
                {   log.error("Cannot handle exception. Exception not supplied with context!");
                    setErrorMessage(context, null);
                    continue;
                }    

                // find root
                rootCause = t.getCause();
                // second option: getRootCause
                if (rootCause == null)
                {   // get cause
                    rootCause = getRootCause(t);
                }
                // third option: use t
                if (rootCause == null)
                {
                    rootCause = t;
                }
                
                // Walk up the tree
                while (true)
                {   // if its an empire-exception: game over
                    if (rootCause instanceof EmpireException)
                        break;
                    // has root cause
                    t = rootCause.getCause();
                    if (t==null)
                        break; 
                    // yes, continue search
                    rootCause = t;
                }
                
                /*
                if (rootCause instanceof org.icefaces.application.SessionExpiredException)
                {   // expired
                    log.info("Handling SessionExpiredException. No error message is set.");
                    continue;
                }
                */

                // set message
                String msg = "Handling exception of type "+rootCause.getClass().getSimpleName();
                // log
                // msg = appendSessionInfo(context, msg);
                log.error(msg, rootCause);
                
                // set message
                if (!(rootCause instanceof EmpireException))
                {   // Wrap as internal exception
                    rootCause = new InternalException(rootCause);
                }
                setErrorMessage(context, rootCause);
                
            } catch(Throwable t2) {
                log.error("Failed to handle exception: "+t2.getMessage(), t2);
            } finally {
                events.remove();
            }
        }

        // if an error has been found
        /*
        if (redirectToErrorPage)
        {
            HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
            try
            {
                // put error to session map (will be cleared by ErrorPage)
                if (rootCause != null)
                {
                    FacesUtils.getFin2Session().setError(rootCause);
                }
                // redirect to error page
                String errorPage = FacesUtils.getContextPath() + "/pages/error.iface";
                Fin2ExceptionHandler.log.debug("Redirecting to error page at '" + errorPage + "'...");
                FacesUtils.redirectDirectly(errorPage);
            }
            catch (Exception e)
            {
                Fin2ExceptionHandler.log.error("Error during exception handling.", e);
                throw new FacesException(e);
            }
        }
        */
        // let next handler deal
        getWrapped().handle();
    }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



