Announcement Announcement Module
Collapse
No announcement yet.
Exception handling with AOP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    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?

    Comment


    • #3
      Originally posted by litterat View Post
      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

      is it possible doing AOP?
      Do I need to proxy every object I want this behaver to apply to?
      If you are using just Spring AOP you do indeed need to proxy each object. However, Spring 2.0+ has easy ways of doing that. You can specify all of your objects normally and then use the aop tags to use a pointcut expression to name all of the objects you want to apply your advise to. The proxying is done automatically.

      Comment


      • #4
        Actually its possible with Spring 1.2 as well. Just requires a little more XML using the right BeanPostProcessor that does auto proxying.

        Comment

        Working...
        X