ExceptionHandler is the central
point for handling unexpected Exceptions that
are thrown during the Faces lifecycle. The
ExceptionHandler must not be notified of any
Exceptions that occur during application startup or
shutdown.
See the specification prose document for the requirements for the
default implementation. Exceptions may be passed to the
ExceptionHandler in one of two ways:
by ensuring that Exceptions are not caught, or
are caught and re-thrown.
This approach allows the ExceptionHandler
facility specified in section JSF.6.2 to operate on the
Exception.
By using the system event facility to publish an ExceptionQueuedEvent that wraps the Exception.
This approach requires manually publishing the ExceptionQueuedEvent, but allows more information about the
Exceptionto be stored in the event. The
following code is an example of how to do this.
//...
} catch (Exception e) {
FacesContext ctx = FacesContext.getCurrentInstance();
ExceptionQueuedEventContext eventContext = new ExceptionQueuedEventContext(ctx, e);
eventContext.getAttributes().put("key", "value");
ctx.getApplication().publishEvent(ExceptionQueuedEvent.class, eventContext);
}
Because the Exception must not be re-thrown
when using this approach, lifecycle processing may continue
as normal, allowing more Exceptions to be
published if necessary.
With either approach, any ExceptionQueuedEvent instances
that are published in this way are accessible to the handle
method, which is called at the end of each lifecycle phase, as
specified in section JSF.6.2.
Note that if handle happens to
be invoked during javax.faces.event.PhaseId#RENDER_RESPONSE,
the recovery options are more limited than when it is invoked during
other phases. Specifically, it is not valid to call javax.faces.application.NavigationHandler#handleNavigation during
RENDER_RESPONSE.
Instances of this class are request scoped and are created by
virtue of FacesContextFactory#getFacesContext calling ExceptionHandlerFactory#getExceptionHandler.
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public abstract ExceptionQueuedEvent | Returns: instance ofExceptionQueuedEvent.Return the first
|
| public abstract Iterable | Returns: anIterable over all ExceptionQueuedEvents.The default implementation must
return an |
| public abstract Throwable | Returns: unwrapped object.passed-in wrapped t)Throwable.Unwrap the argument |
| public abstract Iterable | Returns: the unhandled set ofExceptionQueuedEvents.Return an |
| public abstract void | handle()
Take action to handle the
|
| public abstract boolean | isListenerForSource(Object
the source that is inquiring about the
appropriateness of sending an event to this listener instance. source)Redeclares javax. This method must return |
| public abstract void | processEvent(SystemEvent
the exceptionQueuedEvent)SystemEvent instance that
is being processed.Redeclares javax. When called, the listener can assume that any guarantees given
in the javadoc for the specific |
| ExceptionHandler | back to summary |
|---|---|
| public ExceptionHandler() | |
| getHandledExceptionQueuedEvent | back to summary |
|---|---|
| public abstract ExceptionQueuedEvent getHandledExceptionQueuedEvent() Return the first
| |
| getHandledExceptionQueuedEvents | back to summary |
|---|---|
| public abstract Iterable The default implementation must
return an
| |
| getRootCause | back to summary |
|---|---|
| public abstract Throwable getRootCause(Throwable t) Unwrap the argument
| |
| getUnhandledExceptionQueuedEvents | back to summary |
|---|---|
| public abstract Iterable Return an
| |
| handle | back to summary |
|---|---|
| public abstract void handle() throws FacesException Take action to handle the
| |
| isListenerForSource | back to summary |
|---|---|
| public abstract boolean isListenerForSource(Object source) Redeclares javax. Doc from javax. This method must return | |
| processEvent | back to summary |
|---|---|
| public abstract void processEvent(SystemEvent exceptionQueuedEvent) throws AbortProcessingException Redeclares javax. Doc from javax. When called, the listener can assume that any guarantees given
in the javadoc for the specific
| |