A, @ ControllerAdvice Notes: Write a class, plus
二、@ExceptionHandler(value=Exception.class)
Create exception handling, methods need to add @ExceptionHandler (value = Exception.class) notes, handle exceptions in which method
Third, for example,
We first need to throw RuntimeException at a specified point
catch (Exception e) {
LOGGER.error("密文加密失败"+e.getMessage(),e);
throw new RuntimeException("密文加密失败");
}
/**
* description 拦截未知的运行时异常
*
* @param e 1
* @return com.usthe.bootshiro.domain.vo.Message
*/
@ExceptionHandler(RuntimeException.class)
@ResponseStatus(HttpStatus.OK)
public Message notFoundException(RuntimeException e) {
LOGGER.error("运行时异常:",e);
return new Message().error(1111,"服务器开小差");
}