Hi, I’m trying to program a client application based on the SharedCanvasClient example. My current task is to handle the case where the server might not be running. When the server example is not running and I run the client example, it responds with:
java.net.ConnectException: Connection refused: connect
So, I tried the try/catch commands:
try{
c = new Client(this, "127.0.0.1", 12345); // Replace with your server's IP and port
} catch (java.net.ConnectException e){
println("caught it");
}
it responds with:
Unreachable catch block for ConnectException. This exception is never thrown from the try statement body
My goal is to retry, or put a status message up on the screen of the client program if the server can not be reached.
Can someone point me in the right direction to address this?
thank you
That’s more a workaround, but it happened to me and i used the simple class Exception
for it.
Hi, thank you for the reply!
did you mean this:?
try{
c = new Client(this, "127.0.0.1", 12345); // Replace with your server's IP and port
} catch (Exception e){
println("caught it");
}
this gives me the original error I reported.
Or did you mean something else? I’m new to processing/java/etc. so I could be missing something obvious
I think the problem is that the Client Constructor starts a new thread, but I have no idea, how to catch exceptions in a thread. Processing tries to follow the exception in your code, and if threads point outside of your sketchfolder, just your “thread caller” ist highlighted.
Python for example does not matter if it is in your code, and a looong exception is shown to the mattering script.
Thanks again for your input! It sort of makes sense to me…
I’ll do some more research and if I find a solution I will post.
1 Like
Hi glv!
Thank you so much for the solution to my problem!
Kind of embarrassing, I looked through the net library reference and did not notice active().
cheers,