Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Re: Aspect and Exception Handle

Hi,

If you have a situation like this:

class Foo {
   public void boo() {
       try {
           ...
       }
       catch(Exception e) {
           ...
       }
   }
}

and you would like to advise the handler, you could have an advice
that is something like the following:

before(Foo foo, Exception e): handler(Exception) && within(Foo)
       && args(e) && this(foo) {
   ...
}

You would then have access to the class via the foo object.  Is this
what you are looking for?  Or did you want to completely remove the
try/catch block via an aspect?

On 10/11/06, Washington Correia <washcpc@xxxxxxxxxxxx> wrote:
Hi ! This is the sample code that i sad in the early message.I hope for your
helps.

// Method in the Class


public void jMenuFileCon_actionPerformed(ActionEvent e) {

....

if(result == CaixaLogon.OK_OPTION){

if (System.getSecurityManager() == null) {

System.setSecurityManager(new RMISecurityManager());

}

try {

UnicastRemoteObject.exportObject(this);

myServerObject = (IJogo) Naming.lookup("rmi://" + servidor.getText() +
"/Serv");

Logon.setEnabled(true);

jMenuFileCon.setEnabled(false);

}

catch (RemoteException ex2) {

message = "Erro ao Iniciar Conexão";

title = "Servidor Indisponível ! :-(" ;

CaixaLogon.showMessageDialog(contentPane,message,title,CaixaLogon.NO_OPTION);

}

catch (MalformedURLException ex2) {

message = "Erro ao Iniciar Conexão";

title = "Servidor Indisponível ! :-(" ;

CaixaLogon.showMessageDialog(contentPane,message,title,CaixaLogon.NO_OPTION);

}

catch (NotBoundException ex2) {

message = "Erro ao Iniciar Conexão";

title = "Servidor Indisponível ! :-(" ;

CaixaLogon.showMessageDialog(contentPane,message,title,CaixaLogon.NO_OPTION);

}

...../////////////////////// end class

}

// Aspect to replace the catch block.

public aspect HandlerTeste {



pointcut erro(): call(*
ClassName.jMenuFileCon_actionPerformed(..));



pointcut erro(): handler(MalformedURLException+);

before(ClassName cl): erro() && target(cl){

// to have access to variables in the class like message,title and
Caixa.Logon to replace the bloc catch to // aspect

System.out.println("Tratamento de runtimeexceptio !!");

System.out.println("Trate o erro aqui !!");

}



}


Thanks !


Regards,

____________________________
Washington Costa P. Correia
CTA/ITA/IEC

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





Back to the top