3

Is there a way to chain @ExceptionHandler with exception throwing?
I'm trying to wrap exceptions throw in request handler methods before sending a response:

@ExceptionHandler(value = JsonParseException.class)
public void handleJsonParseException(JsonParseException e) throws BadRequestException {
    throw new BadRequestException(e);
}

@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ExceptionHandler(value = BadRequestException.class)
public @ResponseBody RestResponse handleBadRequest(BadRequestException e) {
    log.info("Bad REST Request", e);
    return constructErrorResponse(e);
}

So, I'd like to for the handleBadRequest() to catch BadRequestException re-thrown from handleJsonParseException().

With the code above, handleJsonParseException() causes server to return default error page instead of RestResponse.

Is this possible or will I have to put exception wrapping in request handlers' try - catch?

4

1 回答 1

1

不可能:

于 2018-01-08T00:00:39.777 回答