Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ajdt-dev] Advice, raising different exceptions depending on 'pointcut'

#: iyad issa changed the world a bit at a time by saying (astral date: 3/30/2006 9:27 AM) :#
you can do this

void around():execution( void *.setData(..)){
            try{
                proceed();
           }catch(Throwable raisedExc){
               throw new ConcernRuntimeException(raisedExc)
           }
}

p.s you can only do this if ConcernRuntimeException is a RuntimeException



As far as I understood, unfortunatelly this will not work, because the initial code (the one triggered/called with proceed) is not throwing by default an exception.

Marco tries to identify what exception is in the signature of the join point, so that his
ConcernRuntimeException will wrap exactly that one.

I guess you can use the thisJoinPointStaticPart to retrieve the MethodSignature and from that one you can access the getExceptionTypes() (http://www.eclipse.org/aspectj/doc/released/runtime-api/org/aspectj/lang/reflect/CodeSignature.html#getExceptionTypes()).

I don't know how you will deal with method declaring multiple exceptions and how you will instanciate those exception, but I hope this helps.

./alex
--
.w( the_mindstorm )p.



On 29/03/06, Marco Mistroni <mmistroni@xxxxxxxxx> wrote:
Hello all,
  i have  following usecase..
I need to intercept all calls to   the method setOwner for all ejbs in
package com.myapp.ejbs.
If the owner does not satisfy a certain condition, i need to raise an
exception.
the challenge here is that the exception type to be raised must be the same
exception that
the intercepted pointcut is catching.
Now, i posted some time ago here about raising exception from aspects, and
after that i have
created a ConcernRuntimeException to be raised if my advice raises some
exceptions.
THis exception wraps the original exception so that the calling object will
be able to handle the exception properly.

But in this case, my pointcut will intercept methods of different EJBs,
which raise potentially
different exceptions..
I have some constraints for NOT to change so that all ejbs intercepted
methods raise exactly the same
exception.

I was wondering if, instead, i use static information from the pointcut to
get the Exception raised by
the intercepted method..
i saw something named  CatchClauseSignature... i was wondering if it could
be useful.....

here's sample of intercepted methods

EJBX {

  public void setData(XData data) throws XException {
          ....
   }
}

EJBY {

   public void setData(YData data) throws YException {
           ....
    }
 }


i was wondering, thus, if i use the CatchClauseSignature, i could
then put following code

 Exception raisedExc =
thisJoinPoint.getSignature().getCatchClauseSignature().getParameterType();

throw new ConcernRuntimeException(raisedExc)

so i can raise a ConcernRuntimeException that could wrap XExceptiopn and
YException...

wil this work?

thanx in advance and regards for you comments

 marco











_______________________________________________
ajdt-dev mailing list
ajdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ajdt-dev



_______________________________________________
ajdt-dev mailing list
ajdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ajdt-dev




Back to the top