Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Catch with AspectJ

Hi
 
A minor improvement:
 
 
public Aspect ExceptionTrace
{
            pointcut traceException(): execution(* A.*(..)) and !within(ExceptionTrace);
            after() throwing(Throwable ex)  : traceException() {
......
 
Catches all errors :) except within the Aspect
 
Hermod


-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx]On Behalf Of ramilani12
Sent: Tuesday, July 31, 2007 2:56 PM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] Catch with AspectJ

I think is good idea use throws any methods your project after use AspectJ for capture this possible Exceptions for Example:


public class A
{
      public void doSomething() throws Exception
      {


      }
 
}


public Aspect ExceptionTrace
{
            pointcut traceException(): execution(* A.*(..));

            after() throwing(Exception ex) :traceException()
            {
                   
                    System.out.println("Exception:");
                    ex.printStackTrace();
            }
     
}

On 7/31/07, Bora Erbas <bora.erbas@xxxxxxxxx> wrote:
Maybe you can use "throws" pcd which might be useful in that case. But
AFAIK, it captures if the method -throws- an exception not -catches-
it. Hence you might need to remove the exception handling code from
the original method and handle it using aspectj.

On 7/31/07, Filipe Costa <filipe.fgcosta@xxxxxxxxx> wrote:
> 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, lake that:
>
> (…)
> catch(<something>Exception e)
>             {
>                 logger.logp(Level.SEVERE , <class name>.class.getName(),
> "method name", e.getMessage());
>             }
>
> Can someone give me an idea?
>
> thank you
>
> fg_costa
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



--
raphael milani
:=]
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

This email with attachments is solely for the use of the individual or
entity to whom it is addressed. Please also be aware that the DnB NOR Group
cannot accept any payment orders or other legally binding correspondence with
customers as a part of an email. 

This email message has been virus checked by the anti virus programs used
in the DnB NOR Group.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Back to the top