lundi 30 mars 2015

Catching DataAccessExceptions with AOP

I have a webapp using Spring + Hibernate through JPA, Spring is effectively translating all persitence exceptions into variations of DataAccessException.


I am now trying to catch these DataAccessExceptions in an AOP pointcut like this:



@Aspect
public class AspectException {


@AfterThrowing(pointcut = "within(com.mypackage.dao..*)", throwing = "error")
public void catchException(Throwable error) {
MyOwnException e = new MyOwnException("ERROR!", error);
throw e;
}
}


Now this aspect works if in my DAO I throw a custom exception, but won't work with Spring's DataAccessExceptions!


Any idea why this is happenning?


Aucun commentaire:

Enregistrer un commentaire