try { // some code } catch (Throwable e) { ExceptionHandler handler = handlers.get(e.getClass()); if (handler != null) handler.handle(e); else DEFAULT_HANDLER.handle(e); } // to be continued
protected Throwable getJSF2UnhandledException(FacesContext facesContext) { Throwable unhandledException = null; ExceptionHandler exceptionHandler = facesContext.getExceptionHandler(); Iterable<ExceptionQueuedEvent> unhandledExceptionQueuedEvents = exceptionHandler.getUnhandledExceptionQueuedEvents(); if (unhandledExceptionQueuedEvents != null) { Iterator<ExceptionQueuedEvent> itr = unhandledExceptionQueuedEvents.iterator(); while (itr.hasNext()) { ExceptionQueuedEvent exceptionQueuedEvent = itr.next(); ExceptionQueuedEventContext exceptionQueuedEventContext = exceptionQueuedEvent.getContext(); unhandledException = exceptionQueuedEventContext.getException(); break; } } return unhandledException; }
protected Throwable getJSF2HandledException(FacesContext facesContext) { Throwable handledException = null; ExceptionHandler exceptionHandler = facesContext.getExceptionHandler(); Iterable<ExceptionQueuedEvent> handledExceptionQueuedEvents = exceptionHandler.getHandledExceptionQueuedEvents(); if (handledExceptionQueuedEvents != null) { Iterator<ExceptionQueuedEvent> itr = handledExceptionQueuedEvents.iterator(); while (itr.hasNext()) { ExceptionQueuedEvent exceptionQueuedEvent = itr.next(); ExceptionQueuedEventContext exceptionQueuedEventContext = exceptionQueuedEvent.getContext(); handledException = exceptionQueuedEventContext.getException(); break; } } return handledException; }
public void handle() throws FacesException { final Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); while (i.hasNext()) { ExceptionQueuedEvent event = i.next(); ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource(); Throwable t = context.getException(); final FacesContext fc = FacesContext.getCurrentInstance(); final ExternalContext externalContext = fc.getExternalContext(); final ConfigurableNavigationHandler nav = (ConfigurableNavigationHandler) fc.getApplication().getNavigationHandler(); try { log.error(t.getMessage(), t); performRedirect(externalContext, "/error_service.htm"); fc.renderResponse(); } finally { i.remove(); } } getWrapped().handle(); }
public void handle() throws FacesException { FacesContext fc = FacesContext.getCurrentInstance(); for (Iterator<ExceptionQueuedEvent> iter = getUnhandledExceptionQueuedEvents().iterator(); iter.hasNext(); ) { ExceptionQueuedEvent event = iter.next(); ExceptionQueuedEventContext queueContext = (ExceptionQueuedEventContext) event.getSource(); Throwable ex = queueContext.getException(); //walk back to the original cause of the exception while (ex.getCause() != null) { ex = ex.getCause(); } String redirectURL = mapping.get(ex.getClass()); if (redirectURL != null) { PartialResponseWriter writer = fc.getPartialViewContext().getPartialResponseWriter(); String uri = fc.getApplication().getViewHandler().getResourceURL(fc, redirectURL); try { writer.startDocument(); writer.redirect(uri); writer.endDocument(); fc.responseComplete(); return; } catch (IOException e) { throw new FacesException(e); } } } handler.handle(); }
(ExceptionQueuedEventContext) exceptionQueuedEventIterator.next().getSource(); Throwable throwable = exceptionQueuedEventContext.getException(); FacesContext facesContext = exceptionQueuedEventContext.getContext(); Flash flash = facesContext.getExternalContext().getFlash(); if (facesContext.getViewRoot() != null) viewId = facesContext.getViewRoot().getViewId(); this.wrapped.handle();
@Override public void handle() throws FacesException { final FacesContext facesContext = FacesContext.getCurrentInstance(); && facesContext.getPartialViewContext().isAjaxRequest() && getUnhandledExceptionQueuedEvents().iterator().hasNext()) { final Throwable exception = getUnhandledExceptionQueuedEvents().iterator().next().getContext().getException(); && (facesContext.getCurrentPhaseId() != PhaseId.RENDER_RESPONSE || !facesContext.getExternalContext().isResponseCommitted())) { getWrapped().handle();
ExceptionQueuedEvent event = it.next(); ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event .getSource(); FacesContext facesContext = FacesContext.getCurrentInstance(); ResourceBundle bundle = facesContext.getApplication() .getResourceBundle(facesContext, "msg"); Throwable t = context.getException(); Throwable cause = ExceptionUtils.getRootCause(t); facesContext.addMessage(null, new FacesMessage( FacesMessage.SEVERITY_ERROR, title, message)); getWrapped().handle();
ExceptionQueuedEventContext eventContext = new ExceptionQueuedEventContext(context, t); context.getApplication().publishEvent(context, ExceptionQueuedEvent.class, eventContext); context.getExceptionHandler().handle(); } finally { ApplicationAssociate.setCurrentInstance(null);
@Override public void handle() throws FacesException { FacesContext facesContext = FacesContext.getCurrentInstance(); ExceptionQueuedEventContext exceptionContext; Throwable root; for (Iterator<ExceptionQueuedEvent> iter = getUnhandledExceptionQueuedEvents().iterator(); iter.hasNext();) { exceptionContext = (ExceptionQueuedEventContext) iter.next().getSource(); root = getRoot(exceptionContext.getException()); if (handleException(root, facesContext)) { iter.remove(); } } if (getUnhandledExceptionQueuedEvents().iterator().hasNext()) { getWrapped().handle(); } }
@Override public void handle() throws FacesException { FacesContext context = FacesContext.getCurrentInstance(); findErrorMessages(context); handleException(context); wrapped.handle(); }
@Override public void handle() throws FacesException { Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); while (i.hasNext()) { ExceptionQueuedEvent event = i.next(); ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource(); // get the exception from context Throwable t = context.getException(); if (NonexistentConversationException.class.isInstance(t)) { i.remove(); throw RuntimeException.class.cast(t); } } delegate.handle(); } }
/** * Set every exception as a global FATAL faces message. */ @Override public void handle() { for (Iterator<ExceptionQueuedEvent> iter = getUnhandledExceptionQueuedEvents().iterator(); iter.hasNext();) { addGlobal(new FacesMessage(SEVERITY_FATAL, createFatalMessage(iter.next().getContext().getException()), null)); iter.remove(); } getWrapped().handle(); }
public static void handleExceptions(FacesContext facesContext) { facesContext.getExceptionHandler().handle(); }
private boolean isUnhandledExceptionQueued(FacesContext context) { return context.getExceptionHandler().getUnhandledExceptionQueuedEvents() != null && context.getExceptionHandler().getUnhandledExceptionQueuedEvents().iterator().hasNext(); }
@Override public Iterable<ExceptionQueuedEvent> getUnhandledExceptionQueuedEvents() { return getWrapped().getUnhandledExceptionQueuedEvents(); }
/** * <p>The default behavior of this method is to call * {@link ExceptionHandler#getHandledExceptionQueuedEvents()} on the wrapped * {@link ExceptionHandler} object.</p> * * @see ExceptionHandler#getHandledExceptionQueuedEvents() */ @Override public Iterable<ExceptionQueuedEvent> getHandledExceptionQueuedEvents() { return getWrapped().getHandledExceptionQueuedEvents(); }
/** * <p>The default behavior of this method is to * call {@link javax.faces.context.ExceptionHandler#processEvent(javax.faces.event.SystemEvent)} * on the wrapped {@link ExceptionHandler} object.</p> * * @see javax.faces.context.ExceptionHandler#processEvent(javax.faces.event.SystemEvent) */ @Override public void processEvent(SystemEvent event) throws AbortProcessingException { getWrapped().processEvent(event); }
/** * <p>The default behavior of this method is to * call {@link javax.faces.context.ExceptionHandler#getRootCause(Throwable)} * on the wrapped {@link ExceptionHandler} object.</p> * * @see javax.faces.context.ExceptionHandler#getRootCause(Throwable) */ @Override public Throwable getRootCause(Throwable t) { return getWrapped().getRootCause(t); }
/** * <p>The default behavior of this method is to * call {@link ExceptionHandler#getHandledExceptionQueuedEvent()} * on the wrapped {@link ExceptionHandler} object.</p> * * @see ExceptionHandler#getHandledExceptionQueuedEvent() */ @Override public ExceptionQueuedEvent getHandledExceptionQueuedEvent() { return getWrapped().getHandledExceptionQueuedEvent(); }