后台异常处理
在开发过程中,不可避免的是需要处理各种异常,异常处理方法随处可见,所以代码中就会出现大量的try {...} catch {...} finally {...}
代码块,不仅会造成大量的冗余代码,而且还影响代码的可读性,所以对异常统一处理非常有必要。为此,我们定义了一个统一的异常类YamiShopBindException
与异常管理类 DefaultExceptionHandlerConfig
。
我们先来看下 YamiShopBindException
的代码
public class YamiShopBindException extends RuntimeException {
private static final long serialVersionUID = -4137688758944857209L;
/**
* http状态码
*/
private Integer httpStatusCode;
/**
* @param httpStatus http状态码
*/
public YamiShopBindException(YamiHttpStatus httpStatus) {
super(httpStatus.getMsg());
this.httpStatusCode = httpStatus.value();
}
/**
* @param httpStatus http状态码
*/
public YamiShopBindException(YamiHttpStatus httpStatus, String msg) {
super(msg);
this.httpStatusCode