title: Kotlin's URL.readText() crashes when I turn my phone's internet off
body: <p>I am doing an HTTP GET request using Kotlin's <code>URL.readText()</code> in an <em>AsyncTask</em>. I'm not making the common mistake of networking in the UI thread, yet my app still experiences crashes.</p>
  
  <p>If I start my app with internet off or turn internet off during operation, it crashes the next time I indirectly trigger a GET request with user input. What is a good way to do a "safe" GET request that just returns an empty String for example instead of crashing?</p>
  
  <p>I separated each call into its own line to make sure it was <code>readText()</code> causing the crash, and not for example the GoogleMap I also use. I also checked the URL object and it is not null. The app does not request any permissions.</p>
  
  <hr>
  
  <p>Task:</p>
  
  <pre><code>class MyTask(map : GoogleMap, url : String) : AsyncTask&lt;Void, Void, String&gt;() {
      val mMap = map;
      val mURL = url;
  
      override fun doInBackground(vararg params: Void?): String {
          return URL(mURL).readText()
      }
  
      ... (more code) ...
  }
  </code></pre>
  
  <p>UI Thread:</p>
  
  <pre><code>MyTask(mMap, url).execute()
  </code></pre>
  
  <p>Log:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
  </code></pre>