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?

-------------Problems Reply------------

Have you throught about exception translation?

Category:java Views:2 Time:2017-09-11

Related post

Copyright (C), All Rights Reserved.

processed in 0.159 (s). 10 q(s)