Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] aspect for Catch Exception

Hi

I'm starting with AspectJ and I have a lot of packages and in which them java classes. I want to do an aspect that capture every exceptions and do something like that:

logger.logp(Level.SEVERE, <class name>.class.getName(), "method name", e.getMessage());

Because every exceptions has a same kind of catch, like that:
 
(…)
catch(<something>Exception e)
            {
                logger.logp(Level.SEVERE, <class name>, <method name>, e.getMessage());
            }  

I have this aspect:

import java.util.logging.Logger;

public aspect Catch_Exc {

    Logger log = Logger.global;
   
    public pointcut detect():
        call(public * *.*(..));
   
    after() throwing (Exception e): detect()
    {

        logger.logp(Level.SEVERE,
                         thisJoinPoint.getSignature().getDeclaringType().getName(), //for class name
                        <method name>,  //for method name???
                        e.getMessage());
     } 
}

Can I know the method name that throws the exception, someone have an idea?

thank you


--
fg_costa
[Filipe Costa]

Back to the top