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

It seems little bit late, hope you already got the solution.

this thisJoinPoint.getSignature() can be casted into different types in package org.aspectj.lang.reflect to get additional information.
http://www.eclipse.org/aspectj/doc/released/runtime-api/org/aspectj/lang/reflect/package-summary.html

For your situation, ((MethodSignature)thisJoinPoint.getSignature()).getName() should work.

Regards,
--
Dehua (Andy) Zhang
Sable Research Group, McGill University
Montréal, Québec, Canada
http://www.cs.mcgill.ca/~dzhang25





-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx on behalf of Filipe Costa
Sent: Thu 8/30/2007 06:37
To: aspectj-users@xxxxxxxxxxx
Subject: [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]