Este contenido no está disponible en el idioma seleccionado.

Chapter 24. Exception Handling


24.1. Exception Mappers

ExceptionMappers are custom, application-provided components that can catch application exceptions and write specific HTTP responses. They are associated with @Provider, and implement the following interface:
         package javax.ws.rs.ext;

         import javax.ws.rs.core.Response;

         /**
         * Contract for a provider that maps Java exceptions to
         * {@link javax.ws.rs.core.Response}. An implementation of this interface must
         * be annotated with {@link Provider}.
         *
         * @see Provider
         * @see javax.ws.rs.core.Response
         */
         public interface ExceptionMapper<E>
         {

         /**
         * Map an exception to a {@link javax.ws.rs.core.Response}.
         *
         * @param exception the exception to map to a response
         * @return a response mapped from the supplied exception
         */
         Response toResponse(E exception);
         }
Copy to Clipboard Toggle word wrap
When an application throws an exception, the exception is caught by the JAX-RS runtime. JAX-RS then scans registered ExceptionMappers to locate one which supports marshalling the exception type thrown. An example ExceptionMapper follows:
         @Provider
         public class EJBExceptionMapper implements ExceptionMapper<javax.ejb.EJBException>
         {

         Response toResponse(EJBException exception) {
         return Response.status(500).build();
         }

         }
Copy to Clipboard Toggle word wrap
ExceptionMappers are registered in the same way as MessageBodyReaders and MessageBodyWriters: by scanning through the RESTEasy provider context-param (if you are deploying in a WAR file), or programmatically through the ResteasyProviderFactory class.
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat