简体   繁体   中英

DataAccessException couldn't catch

My code has a DataAccessException , but it couldn't be caught, Why?

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();
}

exception like this:

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);
        }
    });
}

The exception occues here ,how to catch it ?

My code has a DataAccessException , but it couldn't be caught, Why?

Some possible explanations are:

  • Because the exception wasn't thrown within that try / catch; ie it was thrown somewhere else. (A careful reading of the complete stacktrace will tell you if this is true.)

  • Because there are multiple exceptions called DataAccessException (in different packages) and you are trying to catch the wrong one. (A careful reading of the complete stacktrace AND you code will tell you if this is true.)

  • Because you somehow have managed to load the DataAccessException multiple times. (This can only happen if your application or framework uses different classloader chains in different contexts; eg a typical web container will do this if you have multiple webapps.)


You commented thus:

there is no catch anywhere except this.

That could be the problem. If the exception is not thrown in the context of this try / catch, then this try / catch won't be able to catch it! However, unless you post the complete stacktrace for an exception that isn't being caught, we won't be able to help you with that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM