1 回答

TA贡献1795条经验 获得超7个赞
您可以通过以下方式检查异常是否是 HibernateException 的实例:
@ExceptionHandler(RuntimeException.class)
public String handleRuntimeExceptions(RuntimeException exc, Model theModel) {
if (exc instanceof HibernateException) {
return handleHibernateException((HibernateException) exc.getCause(), theModel);
} else if (exc.getCause() instanceof HibernateException) {
HibernateException hibernateException = (HibernateException) exc.getCause();
return handleHibernateException(hibernateException, theModel);
}
String message = "An error has occurred: " + exc.getLocalizedMessage() + "\n" + exc.getCause().toString() + "\r\n";
myLogger.warning(message);
theModel.addAttribute("exception", message);
return "testing";
}
添加回答
举报