title: Async task crashes the aplication on android when internet is unavailable
body: <p>In my android app I've used a async task to handle my internet request. I achieved that by using the <a href="http://square.github.io/okhttp/" rel="nofollow">okhttp library</a>, which makes it easy to make internet requests. I have a lot of the code surrounded my try/catch statements, but they somehow do not trigger when there is an unhandled exception so the app crashes. That only happens when the internet is disconnected or is slow in areas.</p>
  
  <p>I've looked for similar posts, but found out that people who had the same problems didn't try/catch, so the exceptions weren't handled
  I've also tried to make a checker for the internet accessibility, but that didn't work out too well, because i would much rather do it with clean try-catching.</p>
  
  <pre><code>private class prenesi extends AsyncTask&lt;String, Void, String&gt;
  {
      String odgovor = null;
      protected String doInBackground(String... params)
      {
          OkHttpClient client = new OkHttpClient();
  
          RequestBody vsebina = new FormEncodingBuilder()
                  .add("kraj", params[0])
                  .build();
  
  
          Request request = new Request.Builder()
                  .url("http://mypage.com/login.php")
                  .post(vsebina)
                  .build();
  
          Response response = null;
  
          try
          {
              response = client.newCall(request).execute();
          }
          catch (IOException e)
          {
              e.printStackTrace();
          }
  
          if (!response.isSuccessful())
          {
              odgovor = "Napaka.";
          }
          else
              try
              {
                  odgovor = response.body().string();
              }
              catch (IOException e)
              {
                  e.printStackTrace();
              }
          return odgovor;
      }
  }
  </code></pre>
  
  <p>The devconsole says the problem is in the doInBackground() and i guess it caused because the null pointer exception, though I'm not entirely sure what that means:</p>
  
  <blockquote>
    <p>java.lang.RuntimeException: An error occured while executing doInBackground()
                                                                                   at android.os.AsyncTask$3.done(AsyncTask.java:299)
                                                                                   at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
                                                                                   at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
                                                                                   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
                                                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:137)
                                                                                   at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
                                                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
                                                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
                                                                                   at java.lang.Thread.run(Thread.java:856)
                                                                                Caused by: java.lang.NullPointerException</p>
  </blockquote>
  
  <p>Could somebody point me towards the flaw please. I'm stuck with this.
  All the help will be very appreciated, hope to solve this problem soon.
  Thanks for contributing.</p>