Hi,
I'm using the net library and I want to create a Client that connects to a server; if the connection fails I'd like the client to periodically retry to connect untill it succeed; this way, I don't have to worry about whether the server starts running before or after the client.
So, I basically have the following code:
Code:
Client pdclient;
boolean pdclientconnected;
//......
void draw() {
if (!pdclientconnected) {
print(".");
pdclientconnected=true;
try {
pdclient=new Client(this,PDHOST,PDCLIENTPORT);
}
catch (Exception e) {
pdclientconnected=false;
}
}
// ....etc....
}
When I run this sketch, if the server is up and the connection succeeds, all works fine.
However, if the connection fails, I get a java.net.ConnectException, as if I didn't use a try-catch block.
What am I missing? Why isn't the exception caught??
BTW, I tried replacing "catch (Exception e)" with "catch (java.net.ConnectionException e)", but I get the error message:
"Semantic Error: This catch block is unreachable because there is no non-null exception whose type is assignable to "java.net.ConnectException" that can be thrown during execution of the body of the try block."
Thanks in advance,
Matteo