Annotation for handling exceptions in controller classes and/or handler methods.
Handler methods which are annotated with this annotation are allowed to have very flexible signatures. They may have parameters of the following types:
- An exception argument: declared as a general Exception or as a more specific exception.
This also serves as a mapping hint if the annotation itself does not narrow the exception
types through its
value()
. - Request and/or response objects (typically from the microframework). You may choose any
specific request/response type, e.g. Javalin's
io.javalin.Context
or Helidon's ServerRequest/ServerResponse.
Handler methods may be void or return an object for serialization.
You may combine the ExceptionHandler
annotation with @Produces
for a
specific HTTP error status and media type.
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionint
The response status code to use.Exception handled by the annotated method.
-
Element Details
-
value
Exception handled by the annotated method. If empty, will default to any exception listed in the method argument list.- Default:
io.avaje.http.api.DefaultException.class
-
statusCode
int statusCodeThe response status code to use.- Default:
0
-