Annotation Type ExceptionHandler
Marks a method that answers for an exception a controller method threw.
On a @RestController or @Controller it handles that controller's
routes only, and is consulted first; on a ControllerAdvice bean it handles
every controller's. Among the handlers of one class, the one naming the
closest superclass of the thrown exception is chosen. The order, and the
security failures no handler ever sees, are described on
com.codename1.backend.web.ControllerHooks.
@ExceptionHandler(NotFound.class)
@ResponseStatus(404)
public Map notFound(NotFound e) {
return Collections.singletonMap("error", e.getMessage());
}
The method is public and may take, in any order, the exception (any type
the declared exceptions are assignable to), the HttpServer.Request and the
com.codename1.backend.web.HandlerMethod. It returns an HttpServer.Response
-- complete control of status, headers and body -- or a String (text), a
Map, a List or a Json.Writable (JSON), or nothing; any of those but a
Response is sent with ResponseStatus's status, 200 without one, as in
Spring.
-
Optional Element Summary
Optional Elements
-
Element Details
-
value
Class<?>[] valueThe exceptions handled. Empty means the method's exception parameter's type.- Default:
{}
-