Controller 抛出异常无法匹配:
1、 throw new BasicException();可以匹配;
2、 throw new RuntimeException();无法匹配;
是哪里写错了吗?以下是部分代码
控制器Web接口异常处理类 ExceptionHandler:
@ExceptionHandler(BasicException.class) //自定义数据异常
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public ResultDataView<?> BasicException(BasicException e) {
log.error(e.getErrMsg());
return ResultDataView.failure(e.getErrMsg());
}
自定义异常类:
public class BasicException extends RuntimeException {
private static final long serialVersionUID = -2789674242371703555L;
protected String errMsg;
public BasicException() {
}
public BasicException(String errMsg) {
this.errMsg = errMsg;
}
public String getErrMsg() {
return errMsg;
}
public void setErrMsg(String errMsg) {
this.errMsg = errMsg;
}
}
目测没写专门匹配RuntimeException的方法啊,所以就没有喽