title: When is a connection timedout exception thrown in java?
body: <p>This is my code : <br></p>
  
  <pre><code>connection.setConnectTimeout(5000);
  ObjectOutputStream out=new ObjectOutputStream(connection.getOutputStream());
  out.writeObject(to_be_sent);
  out.flush();
  out.close();
  int resp_code=connection.getResponseCode();
  if(resp_code==200)
  {
   JOptionPane.showMessageDialog(obj.frame, "Your Application has been sent Successfully");
  }
  </code></pre>
  
  <p>As you can see I have set the connection timeout to be 5 seconds. I want to know when this connection time exception is thrown and which line throws it. Is it thrown when connection.getResponseCode() does not return anything for 5 seconds?
  <br><strong>Edit</strong><br>Looked up javadocs just now and found out that getResponse code only throws <code>IOException</code> when not able to connect to the server.<br></p>