Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Trace method calls with around advice

Hello!

I want to trace method calls using an around advice. It is important that I can associate method calls and their return value and a thrown exception, respectively. So, using before and after advices does not meet my requirements (without using the stack information).

An advice like the following could do the job:


   Object around() throws Exception: aCall() {
logger.trace("Before proceed: " + thisJoinPoint); int id = Manager.record(thisJoinPoint);

       Object returned = null;
try {
           returned = proceed();
       } catch (Exception e) {
           logger.trace("After proceed: " + thisJoinPoint);
           logger.trace("Threw an exception: " + e);
           Manager.recordException(id, e);
           throw e;
       }

       logger.trace("After proceed: " + thisJoinPoint);
       logger.trace("Returned normally with " + returned);

       Manager.record(id, returned);
return returned;
   }


Unfortunately, that advice does not work. Using an RuntimeException will not handle method with checked exceptions.

Is there any way to do this job using AspectJ?

Regards,
   Martin


Back to the top