I am new to AOP and have been trying to create an AOP-based exception handling framework for my application. I know this question has been asked in these forums before, but I have not been able to determine why exceptions thrown in the code are not being logged. Essentially, I am just trying to log all exceptions that are thrown in the com.foo.bar package.
Configuration:
ErrorHandler:Code:<bean id="errorHandler" class="com.foo.bar.arch.error.ErrorHandler"/> <aop:aspectj-autoproxy/> <aop:config> <aop:after-throwing pointcut="within(com.foo.bar..*)" throwing="exception" method="processError"/> </aop:aspect> </aop:config>
In order to test this, I am simply throwing a MyException in my test code:Code:public final class ErrorHandler { ... public void processError(JoinPoint logged, MyException exception) { logger.error(exception.getCause().getMessage()); } ... }
Am I incorrect in catching the exception here? My understanding was that it would still be logged.Code:public void testAOPErrorHandling() { try { throw new MyException("something"); } catch(MyException e) { // do something } }
Thanks!


Reply With Quote