javax.faces.context

Class 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 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.

    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) calling ExceptionHandlerFactory.getExceptionHandler().

    Since:
    2.0
    • Constructor Detail

      • ExceptionHandler

        public ExceptionHandler()
    • Method Detail

      • handle

        public abstract void handle()
                             throws FacesException

        Take action to handle the Exception instances residing inside the ExceptionQueuedEvent instances that have been queued by calls to Application().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 the Exception, not as a means of conveying a handled Exception 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 all ExceptionQueuedEvents that have not yet been handled by the handle() method.

      • getHandledExceptionQueuedEvents

        public abstract Iterable<ExceptionQueuedEvent> getHandledExceptionQueuedEvents()

        The default implementation must return an Iterable over all ExceptionQueuedEvents that have been handled by the handle() method.

      • 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 the source parameter.

        Specified by:
        isListenerForSource in interface SystemEventListener
        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 whose getClass() is not equal to FacesException.class or javax.el.ELException.class. If there is no root cause, null is returned.

        Throws:
        NullPointerException - if argument t is null.
        Since:
        2.0

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 11/06/2005 gemaakt, de laatste keer de 18/08/2025 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/java-api-javaee-rf-javax/faces/context/ExceptionHandler.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.

Referenties

  1. Bekijk - html-document Taal van het document:fr Manuel PHP : https://docs.oracle.com, ExceptionHandler (Java(TM) EE 7 Specification APIs)

Deze verwijzingen en links verwijzen naar documenten die geraadpleegd zijn tijdens het schrijven van deze pagina, of die aanvullende informatie kunnen geven, maar de auteurs van deze bronnen kunnen niet verantwoordelijk worden gehouden voor de inhoud van deze pagina.
De auteur van deze site is als enige verantwoordelijk voor de manier waarop de verschillende concepten, en de vrijheden die met de referentiewerken worden genomen, hier worden gepresenteerd. Vergeet niet dat u meerdere broninformatie moet doorgeven om het risico op fouten te verkleinen.