String requestType = request.getHeader(“X-Requested-With”);
// 根据不同错误转向不同页面
if (ex instanceof BusinessException) {
} else if(ex instanceof SystemException) {
return "m/bind";
} else if (ex instanceof DataAccessException) {
ex = new SystemException( "数据库操作失败",ex);
} else if (ex instanceof NullPointerException) {
ex = new SystemException( "调用了未经初始化的对象或者是不存在的对象",ex);
} else if (ex instanceof IOException) {
ex = new SystemException( "IO异常",ex);
} else if (ex instanceof ClassNotFoundException) {
ex = new SystemException( "指定的类不存在",ex);
} else if (ex instanceof ArithmeticException) {
ex = new SystemException( "数学运算异常",ex);
} else if (ex instanceof ArrayIndexOutOfBoundsException) {
ex = new SystemException( "数组下标越界",ex);
} else if (ex instanceof IllegalArgumentException) {
ex = new SystemException( "方法的参数错误",ex);
} else if (ex instanceof ClassCastException) {
ex = new SystemException( "类型强制转换错误",ex);
} else if (ex instanceof SecurityException) {
ex = new SystemException( "违背安全原则异常",ex);
} else if (ex instanceof SQLException) {
ex = new SystemException( "操作数据库异常",ex);
} else if (ex instanceof CannotCreateTransactionException) {
ex = new SystemException("数据库连接失败",ex);
} else if (ex instanceof TransactionSystemException) {
ex = new SystemException( "数据库连接失败",ex);
} else if (ex instanceof UnauthorizedException){
ex = new SystemException("无权进行该操作",ex);
} else if (ex instanceof Exception) {
ex = new SystemException( "程序内部错误,操作失败",ex);
}
request.setAttribute("ex", ex);
if(StringUtils.isNotBlank(requestType)){
//异步请求
return "common/error/systemExceptionAjax";
}
return "common/error/systemException";
}