- java.lang.Object
-
- javax.faces.context.ExceptionHandler
-
- All Implemented Interfaces:
- EventListener, FacesListener, SystemEventListener
- Direct Known Subclasses:
- ExceptionHandlerWrapper
public abstract class ExceptionHandler extends Object implements SystemEventListener
ExceptionHandler is the central point for handling unexpected
Exception
s that are thrown during the Faces lifecycle. TheExceptionHandler
must not be notified of anyException
s that occur during application startup or shutdown.See the specification prose document for the requirements for the default implementation.
Exception
s may be passed to theExceptionHandler
in one of two ways:by ensuring that
Exception
s are not caught, or are caught and re-thrown.This approach allows the
ExceptionHandler
facility specified in section JSF.6.2 to operate on theException
.By using the system event facility to publish an
ExceptionQueuedEvent
that wraps theException
.This approach requires manually publishing the
ExceptionQueuedEvent
, but allows more information about theException
to 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 moreException
s to be published if necessary.
With either approach, any
ExceptionQueuedEvent
instances that are published in this way are accessible to thehandle()
method, which is called at the end of each lifecycle phase, as specified in section JSF.6.2.Instances of this class are request scoped and are created by virtue of
FacesContextFactory.getFacesContext(java.lang.Object, java.lang.Object, java.lang.Object, javax.faces.lifecycle.Lifecycle)
callingExceptionHandlerFactory.getExceptionHandler()
.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor and Description ExceptionHandler()
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description abstract ExceptionQueuedEvent
getHandledExceptionQueuedEvent()
Return the first
ExceptionQueuedEvent
handled by this handler.abstract Iterable<ExceptionQueuedEvent>
getHandledExceptionQueuedEvents()
The default implementation must return an
Iterable
over allExceptionQueuedEvent
s that have been handled by thehandle()
method.abstract Throwable
getRootCause(Throwable t)
Unwrap the argument
t
until the unwrapping encounters an Object whosegetClass()
is not equal toFacesException.class
orjavax.el.ELException.class
.abstract Iterable<ExceptionQueuedEvent>
getUnhandledExceptionQueuedEvents()
Return an
Iterable
over allExceptionQueuedEvent
s that have not yet been handled by thehandle()
method.abstract void
handle()
Take action to handle the
Exception
instances residing inside theExceptionQueuedEvent
instances that have been queued by calls toApplication().publishEvent(ExceptionQueuedEvent.class, eventContext)
.abstract boolean
isListenerForSource(Object source)
This method must returntrue
if and only if this listener instance is interested in receiving events from the instance referenced by thesource
parameter.abstract void
processEvent(SystemEvent exceptionQueuedEvent)
When called, the listener can assume that any guarantees given in the javadoc for the specificSystemEvent
subclass are true.
-
-
-
Method Detail
-
handle
public abstract void handle() throws FacesException
Take action to handle the
Exception
instances residing inside theExceptionQueuedEvent
instances that have been queued by calls toApplication().publishEvent(ExceptionQueuedEvent.class, eventContext)
. The requirements of the default implementation are detailed in section JSF.6.2.1.- Throws:
FacesException
- if and only if a problem occurs while performing the algorithm to handle theException
, not as a means of conveying a handledException
itself.- Since:
- 2.0
-
getHandledExceptionQueuedEvent
public abstract ExceptionQueuedEvent getHandledExceptionQueuedEvent()
Return the first
ExceptionQueuedEvent
handled by this handler.
-
getUnhandledExceptionQueuedEvents
public abstract Iterable<ExceptionQueuedEvent> getUnhandledExceptionQueuedEvents()
Return an
Iterable
over allExceptionQueuedEvent
s that have not yet been handled by thehandle()
method.
-
getHandledExceptionQueuedEvents
public abstract Iterable<ExceptionQueuedEvent> getHandledExceptionQueuedEvents()
The default implementation must return an
Iterable
over allExceptionQueuedEvent
s that have been handled by thehandle()
method.
-
processEvent
public abstract void processEvent(SystemEvent exceptionQueuedEvent) throws AbortProcessingException
When called, the listener can assume that any guarantees given in the javadoc for the specific
SystemEvent
subclass are true.- Specified by:
processEvent
in interfaceSystemEventListener
- Parameters:
exceptionQueuedEvent
- theSystemEvent
instance that is being processed.- Throws:
AbortProcessingException
- if lifecycle processing should cease for this request.
-
isListenerForSource
public abstract boolean isListenerForSource(Object source)
This method must return
true
if and only if this listener instance is interested in receiving events from the instance referenced by thesource
parameter.- Specified by:
isListenerForSource
in interfaceSystemEventListener
- Parameters:
source
- the source that is inquiring about the appropriateness of sending an event to this listener instance.
-
getRootCause
public abstract Throwable getRootCause(Throwable t)
Unwrap the argument
t
until the unwrapping encounters an Object whosegetClass()
is not equal toFacesException.class
orjavax.el.ELException.class
. If there is no root cause,null
is returned.- Throws:
NullPointerException
- if argumentt
isnull
.- Since:
- 2.0
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 18/08/2025
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-javaee-rf-javax/faces/context/ExceptionHandler.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor dieser Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.