Exception handling with AOP
Hi
I would like to be able to catch excpetions in my application process it and then rethrow application spectific exception
Something like Spring do with Hibernate excption
I would like to have one Exception "Brain" which process any excpetion's type and then create an excpetion from the application specifc exception tree
I would like to be able to catch unchecked excption and checked excpetions
and to be able to throw unchecked excption
is it possible doing AOP?
Do I need to proxy every object I want this behaver to apply to?
Thanks in advance
AFter doing some research here is what I came up with
I use an around advisor
Code:
public class SomeMethodInteceptor implements MethodInterceptor {
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
Object result = null;
try {
result = methodInvocation.proceed();
} catch (Exception e) {
doSomething(e);
}
return result;
}
}
I used this configuration
Code:
<bean name="SomeMethodInteceptor"
class="SomeMethodInteceptor class">
</bean>
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>beanPrefix*</value>
</property>
<property name="interceptorNames">
<list>
<value>SomeMethodInteceptor</value>
</list>
</property>
</bean>
and that is it
Can you share your thought about this solution?