[aspectc-user] Throw exception

mike-mortensen at comcast.net mike-mortensen at comcast.net
Tue Feb 19 16:53:11 CET 2008


Would it work to advise the MyExc constructor?  I'm guessing this class is
only use for exceptions, so the MyExc constructor only executes when an exception is thrown.

Or is the (eventual) goal to prevent some excepts from being thrown?

Also, one thing I have done is to use around advice for a function that
has the throw (such as bobo::bla) and have the around advice contain
a try/catch, so that the advice catches the except thrown by the function.

Of course, one problem with advising the functions is that the pointcut
might end up being a list of all the places in the code that could throw
a certain exception, which is a fragile pointcut...  but it is an option for
some cases where aspects can catch the exception.

-Mike

 -------------- Original message ----------------------
From: Daniel Lohmann <daniel.lohmann at informatik.uni-erlangen.de>
> 
> On 18.02.2008, at 11:00, Dima S wrote:
> 
> > Hello all,
> >
> > I want to have a pointcut for throwing C++ exception.
> > I have the following code:
> > class MyExc
> > {
> > public:
> >   MyExc();
> > };
> > MyExc::MyExc()
> > {
> > }
> >
> > class bobo
> > {
> > public:
> > int bobo::bla( int d )
> > {
> >   if( d == 0 )
> >   {
> >      throw MyExc();
> >   }
> >
> >   return d * d;
> > }
> >
> > I define the following pointcut:
> >   pointcut exception() = call( "%throw%" );
> > and corresponding advice:
> >       advice exception(): before ()
> >       {
> >          printf( "\tException is thrown here!");
> >       }
> >
> > However it does not work.
> > Any idea what i should do to get correct advice/pointcut?
> 
> Hi Dima,
> 
> AspectC++ currently does not support giving advice to throw statements.
> 
> If the code throwing the exceptions is under your control, you might  
> consider delegating the throw to an extra (inline)-function and give  
> advice to this function.
> 
> Daniel
> _______________________________________________
> aspectc-user mailing list
> aspectc-user at aspectc.org
> http://www.aspectc.org/mailman/listinfo/aspectc-user




More information about the aspectc-user mailing list