访问exceptionhandler方法中的错误对象

时间:2016-09-29 13:27:08

标签: java error-handling exception-handling exceptionhandler

使用注释@ExceptionHandler时,有没有办法进入异常对象?

这是我的代码:

@ExceptionHandler(DataInputException.class)
    public ResponseEntity handleException(){
         return ResponseEntity
                    .status(HttpStatus.BAD_REQUEST)
                    .body("Entity contains null or forbidden values");
    }

我希望返回包含有关特定字段的自定义信息的消息。 (这就是我需要错误对象的原因)。

1 个答案:

答案 0 :(得分:3)

传递例外

@ExceptionHandler(DataInputException.class)
public ResponseEntity handleException(DataInputException exception) {
相关问题