title: Fatal Exception When Not Connected to Internet
body: <p>I'm trying to learn <code>Kotlin</code> and <code>rxjava</code>. I have a very simple app with just a <code>button</code> that you click that fetches some data from a website.</p>
  
  <p>Everything works fine unless I turn off of my cellular data, in which case I get a fatal exception with no explanation of why.</p>
  
  <blockquote>
    <p>My code:</p>
  </blockquote>
  
  <pre><code>// In the activity's onCreate
  ViewObservable.clicks(button)
          .observeOn(Schedulers.io())
          .subscribe{
              fetchTest().observeOn(AndroidSchedulers.mainThread())
                      .subscribe{ s:String -&gt; 
                          textView.text = s
                      }      
          }
  
  // Elsewhere in the activity code
  @Throws(IOException::class)
  private fun fetchTest(): Observable&lt;String&gt; {
      val url = URL(MY_URL)
      val httpConnection = url.openConnection()
  
      var stream = httpConnection.inputStream
  
      val reader = BufferedReader(InputStreamReader(stream))
  
      val response = reader.readLines().reduce { x, y -&gt; x + y }
      stream?.close()
  
      return Observable.just(response)
  }
  </code></pre>
  
  <blockquote>
    <p>When I'm in debug mode, the error occurs here:</p>
  </blockquote>
  
  <pre><code>var stream = httpConnection.inputStream
  </code></pre>
  
  <p>And the logcat is entirely unhelpful:</p>
  
  <pre><code>02-12 10:13:37.748    8616-8645/com.example.app E/AndroidRuntime﹕ FATAL EXCEPTION: RxCachedThreadScheduler-1
  Process: com.example.app, PID: 8616
  </code></pre>
  
  <p>I know the error is because there's no network connection, but adding a try/catch can't catch it so I don't know what to do</p>