我的代码有一个DataAccessException,但是它不能被捕获,为什么?
CustomerPlan newCust = data.customerPlan;
try {
this.demandService.doCreateCustomerPlanAndDemandForecast(newCust,
newDf);
} catch (DataAccessException de) {
log.info("de ------------------------------------");
de.printStackTrace();
log.info("de end ------------------------");
} catch (Exception le) {
log.info("de ------------------------------------");
le.printStackTrace();
log.info("de end ------------------------");
} catch (Throwable t) {
log.info("tttttttttttttttttttttttt");
t.printStackTrace();
}像这样的例外:
at rmes.service.demand.DemandService.doCreateCustomerPlanAndDemandForecast(DemandService.java:132)@Override
public Serializable save(final Object entity) throws DataAccessException {
return executeWithNativeSession(new HibernateCallback<Serializable>() {
@Override
public Serializable doInHibernate(Session session) throws HibernateException {
checkWriteOperationAllowed(session);
return session.save(entity);
}
});
}异常发生在这里,如何抓住它?
发布于 2014-12-14 07:46:38
我的代码有一个
DataAccessException,但是它不能被捕获,为什么?
一些可能的解释是:
DataAccessException的异常(在不同的包中),所以您试图捕获错误的异常。(仔细阅读完整的堆栈跟踪并编写代码将告诉您这是否属实。)DataAccessException。(只有当您的应用程序或框架在不同的上下文中使用不同的类加载器链时才会发生这种情况;例如,如果您有多个web应用程序,一个典型的web容器就会这样做。)你这样评论:
除了这个,任何地方都没有渔获。
这可能就是问题所在。如果在此try / catch的上下文中没有抛出异常,则此try / catch将无法捕获它!但是,除非您发布未被捕获的异常的完整堆栈跟踪,否则我们将无法帮助您。
https://stackoverflow.com/questions/27467285
复制相似问题