Results 1 to 4 of 4

Thread: Exception handling with AOP

Hybrid View

  1. #1

    Default 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
    mmmm, I think I will order a cup of coffee in this beautiful spring day

  2. #2

    Thumbs up 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?
    mmmm, I think I will order a cup of coffee in this beautiful spring day

  3. #3
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

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

  4. #4
    Join Date
    Feb 2005
    Location
    Boston, MA
    Posts
    1,142

    Default

    Quote 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.
    Bill

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •