title: How to check if OkHttp3 request timed out?
body: <p>I am making an HTTP GET request to a Web Server using the code below:</p>
  
  <pre><code>private final OkHttpClient client = new OkHttpClient();
  
  public void run() throws Exception {
    Request request = new Request.Builder()
        .url("http://publicobject.com/helloworld.txt")
        .build();
  
    Response response = client.newCall(request).execute();
    if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  
    Headers responseHeaders = response.headers();
    for (int i = 0; i &lt; responseHeaders.size(); i++) {
      System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
    }
  
    System.out.println(response.body().string());
  }
  </code></pre>
  
  <p>According to <a href="http://square.github.io/okhttp/3.x/okhttp/" rel="nofollow">OkHttp document</a> as shown below, okhttp3 execute calls will throw IOException if the request could not be executed due to cancellation, a connectivity problem or timeout.</p>
  
  <blockquote>
    <p>Throws:
    IOException - if the request could not be executed due to cancellation, a connectivity problem or timeout. Because networks can fail during an exchange, it is possible that the remote server accepted the request before the failure.</p>
  </blockquote>
  
  <p>I would like to know if there's a way to know if IOException was due to the request getting timed out?</p>