thanks, this has been really helpful.
----- Original Message -----
Sent: Thursday, June 03, 2004 7:46
PM
Subject: Re: [aspectj-dev] using AspectJ
to deal with exceptions
Hi Eric,
You could certainly use AspectJ to modularize the recovery logic, e.g.,
aspect ErrorRecovery {
pointcut socketCreation(int port) : execution(new
ServerSocket(int));
void around(int port) : socketCreation(port) {
boolean retry = true;
do {
try {
proceed(port);
retry = false;
} catch
(BindException e) {
port++;
}
} while (retry);
}
}
This has the benefit of separating your error handling strategy from your
mainline code (better modularity) and it allows the strategy to be revised and
even reused in other places or applications. Admittedly, only typically create
server sockets in one place, so there may not be much crosscutting in
this case. I.e., you avoid tangling, but there may probably is not much
scattering (at least not for a single application).
Ron Bodkin
Chief Technology Officer
New Aspects of Software
o: (415) 824-4690
m: (415) 509-2895
------------Original Message------------
From: "Eric Macaulay" <eeoam@xxxxxxxxx>
To: <aspectj-dev@xxxxxxxxxxx>
Date: Thu, Jun-3-2004 11:25 AM
Subject: [aspectj-dev] using AspectJ to deal with exceptions
I have the following statement:
socket = new ServerSocket(port).
if java.net.BindException is thrown then then
the port is already in which case I wish to increment the port number
and try again. I wish to keep this up until either I get a free port or we
run out of ports.
Can aspectj make this algorithm any
easier/elegant to implement than Java?
Eric
Macaulay