Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] how exception handling works?

Hi,

I am stuck with exception handling in aspectj.

Let's say in a method in the class I execute the following snippet:

void methodSocket() {

try {
  
 socket.connect(new InetSocketAddress(" www.google.de",80),200);
}catch(IOException e)  {
  e.printStackTrace();
}
}

I would like to remove the exception handling from methodSocket and encapsulate it within an aspect as follows:

void methodSocket() {
 socket.connect(new InetSocketAddress("www.google.de",80),20);
}

public aspect SocketAspect {

   pointcut p(): call(* java.net.Socket.connect (..));

 after(): p() {
     throw new IOException();
 }
}

What is wrong with this aspect? How can I achieve my aim?

Thanks in advance

Back to the top