自定义的异常类,用instanceof判断类型错误
自定义了一个继承RuntimeException的类BusinessRunTimeException,在controller捕获的时候,用e instanceof BusinessRunTimeException判断结果返回false
相关代码
业务层直接抛异常:
throw new BusinessRunTimeException();
控制层捕获:
try {
//省略内容
} catch (Exception e) {
if (e instanceof BusinessRunTimeException) {
BusinessRunTimeException b = (BusinessRunTimeException) e;
//省略内容
} else {
//省略内容
}
}