java - ExceptionHandler doesn't work with Throwable -
ours spring mvc based rest application. trying use exceptionhandler annotation handle errors , exceptions.
i have
@exceptionhandler(throwable.class) public @responsebody string handleerrors() { return "error"; }
this works whenever there exception thrown , doesn't work errors.
i using spring 4.0. there work-around?
contrary exceptionhandler#value()
attribute indicates
class<? extends throwable>[] value() default {};
and @exceptionhandler
meant handle exception
, sub types.
spring uses exceptionhandlerexceptionresolver
resolve annotated handlers, using following method
doresolvehandlermethodexception(httpservletrequest request, httpservletresponse response, handlermethod handlermethod, exception exception)
which can see accepts exception
.
you cannot handle throwable
or error
types @exceptionhandler
configuration.
i tell provide own handlerexceptionresolver
implementation handle throwable
instances, you'd need provide own dispatcherservlet
(and of mvc stack) since dispatcherservlet
not catch
throwable
instances @ place make significant difference.
update:
since 4.3, spring mvc wraps thrown throwable
value in nestedservletexception
instance , exposes exceptionhandlerexceptionresolver
.
Comments
Post a Comment