We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › cannot catch exception when "new Client"
Page Index Toggle Pages: 1
cannot catch exception when "new Client" (Read 566 times)
cannot catch exception when "new Client"
Jan 3rd, 2007, 3:01pm
 
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
Page Index Toggle Pages: 1