[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Exception handling without duplicated exceptions caugth

I´m using my solution like above, some suggest??


public aspect LoggingAspect {
    public static final Logger LOG = Logger.getLogger(LoggingAspect.class.getName());
    private List exceptionsHandle = new ArrayList();
    pointcut not_aspect(): !within(com.sena.aspectos..*);

    /**
     * Advice to log all checked exceptions
     */
    after() throwing (Exception ex): execution(* *.*(..)) && not_aspect(){
        Signature sig = thisJoinPointStaticPart.getSignature();
        String dadMethod = getDadStackMethod(ex);
       
        if(!exceptionsHandle.contains(dadMethod)){       
            LOG.logp(Level.SEVERE,  
                        sig.getDeclaringType().getSimpleName(),
                        sig.getName(),
                        ex.toString()+ "\n in ["+ dadMethod + "]");
        }else{
            exceptionsHandle.add(dadMethod);
        }
    }
    /**
     * This method get the first method in project who cause the exception
     */
    private String getDadStackMethod(Exception ex) {
        int stackIndex = 0;
       
        List listaExcecao = new ArrayList(4);
        listaExcecao.add("sun");
        listaExcecao.add("java");
        listaExcecao.add("javax");
        listaExcecao.add("org");
        try{
            while (true) {
                StackTraceElement dadTrace = ex.getStackTrace()[stackIndex++];   
                String excecao = dadTrace.getClassName();
                if(!listaExcecao.contains(excecao.split("\\.")[0])){
                    return dadTrace.toString();
                }
            }
        }catch (Exception e) {
            return (ex.getStackTrace()[0]).toString();
        }
    }
}

--
Thanks, 
Raphael Paiva Fernandes
Sena Informática
Fortaleza - Ceará - Brasil
E-mail: raphael@xxxxxxxxxxx -  Office: : +55 85 3476-8550

 



Raphael Paiva wrote:
I´m implementing an exception handling with aspect but I have a question:

How to ignore duplicated exceptions caugth??

Someone have a good and simple example of an exception handling component in aspectj?


--
Thanks, 
Raphael Paiva Fernandes
Sena Informática
Fortaleza - Ceará - Brasil
E-mail: raphael@xxxxxxxxxxx -  Office: : +55 85 3476-8550

 


_______________________________________________ aspectj-users mailing list aspectj-users@xxxxxxxxxxx https://dev.eclipse.org/mailman/listinfo/aspectj-users