Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.此内容没有您所选择的语言版本。
Chapter 49. Handling Exceptions
Abstract
When possible, exceptions caught by a resource method should cause a useful error to be returned to the requesting consumer. JAX-RS resource methods can throw a
WebApplicationException exception. You can also provide ExceptionMapper<E> implementations to map exceptions to appropriate responses.
49.1. Overview of JAX-RS Exception Classes 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Overview 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
In JAX-RS 1.x, the only available exception class is
WebApplicationException. Since JAX-WS 2.0, however, a number of additional JAX-RS exception classes have been defined.
JAX-RS runtime level exceptions 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The following exceptions are meant to be thrown by the JAX-RS runtime only (that is, you must not throw these exceptions from your application level code):
ProcessingException- (JAX-RS 2.0 only) The
javax.ws.rs.ProcessingExceptioncan be thrown during request processing or during response processing in the JAX-RS runtime. For example, this error could be thrown due to errors in the filter chain or interceptor chain processing. ResponseProcessingException- (JAX-RS 2.0 only) The
javax.ws.rs.client.ResponseProcessingExceptionis a subclass ofProcessingException, which can be thrown when errors occur in the JAX-RS runtime on the client side.
JAX-RS application level exceptions 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The following exceptions are intended to be thrown (and caught) in your application level code:
WebApplicationException- The
javax.ws.rs.WebApplicationExceptionis a generic application level JAX-RS exception, which can be thrown in application code on the server side. This exception type can encapsulate a HTTP status code, an error message, and (optionall) a response message. For details, see Section 49.2, “UsingWebApplicationExceptionexceptions to report errors”. ClientErrorException- (JAX-RS 2.0 only) The
javax.ws.rs.ClientErrorExceptionexception class inherits fromWebApplicationExceptionand is used to encapsulate HTTP4xxstatus codes. ServerErrorException- (JAX-RS 2.0 only) The
javax.ws.rs.ServerErrorExceptionexception class inherits fromWebApplicationExceptionand is used to encapsulate HTTP5xxstatus codes. RedirectionException- (JAX-RS 2.0 only) The
javax.ws.rs.RedirectionExceptionexception class inherits fromWebApplicationExceptionand is used to encapsulate HTTP3xxstatus codes.