title: Java Socket - how to catch Exception of BufferedReader.readline()
body: <p>I have a Thread (let's say T1) which reads data from socket:</p>
  
  <pre><code>public void run() {
    while (running) {
      try {
        BufferedReader reader = new BufferedReader( new InputStreamReader(socket.getInputStream()) ); 
        String input = reader.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  
  }
  </code></pre>
  
  <p>Another Thread (lets say T2) try to finish the program in one of its method. Therefore T2 does the following:</p>
  
  <pre><code>T1.running = false;
  socket.close();
  </code></pre>
  
  <p>Here is this scenario for which i couldn't find a solution:<br/></p>
  
  <ul>
  <li>T1 is active and waiting for some input to read i.e. blocking.</li>
  <li>context switching</li>
  <li>T2 is active and sets running to false, closes the socket</li>
  <li>context switching</li>
  <li>because T1 was blocking and T2 closed the socket, T1 throws an Exception. What i want is to catch this SocketException. i can't put a try/catch(SocketException) in T1.run(). So how can i catch it in T1's running-method? If it's not possible to catch it in T1's running, then how can i catch it elsewhere?</li>
  </ul>
  
  <p>PS: "Another question about the Thread Debugging"<br/>
  Normally when i debug the code step by step, i lose the 'active running line' on a context switch. Let's say i'm in line 20 of T1, context switch happens,  let's assume the program continues from the 30.line of T2, but the debugger does not go/show to the 30.line of T2, instead the 'active running line' vanishes. So i lose the control over the code. I use Eclipse for Java and Visual Studio for C#. So what is the best way to track the code while debugging on a context switch ?</p>