0

I am having a problem with my code which handles whether or not the client has disconnected this is the run method for each thread.
The code gives me an error, something about the nested catch block not ever happening or something. I didn't understand. Thanks for any help. I just want to be able to tell if a client has disconnected from the server while running in a while true loop.

public void run()
{
  try 
  {
     //code that needs to executed once so its not in loop
     while(true)
     {
       try
       {
          //execute server code for servicing client in loop
 
       }
       catch (IOException e) //if the connection is lost will this exception be thrown
       {
      	System.out.println("A Client Has Disconnected");
	break; //break the while loop
        }
      }
   }
   catch (IOException e) //if the execute once code messes up this exception will be thrown
    {
       System.out.println(e);
    }

}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by mellowmike
0

Do you need the catch IOException in the loop? Doesn't the one outside of the loop take care of the same thing? Maybe that's your problem.

Edited by mellowmike: didn't read the code closely enough

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.