RuntimeException handling best practices
<p>RuntimeExceptions are supposed to indicate programming error and I want my application to crash when something inside my observables throws RuntimeException. </p>

<p>What is the best way to do this? Right now I'm considering this solution (it's Kotlin, but I hope it's understandable)</p>

<pre><code>fun &lt;T&gt; Observable&lt;T&gt;.subscribeCrashOnRuntimeException(onNext: (T) -&gt; Unit, onError: (Throwable) -&gt; Unit) {
  this.subscribe({
    onNext(it)
  }, { e -&gt;
    if (e is RuntimeException) {
      throw e
    } else {
      onError(e)
    }
  })
}

fun usageExample() {
  val observable = Observable.just(1)
  observable.subscribeCrashOnRuntimeExceptions(
    { next -&gt; Log.d("TAG", "next: $next") },
    { e -&gt; Log.d("TAG", "error: $e") }
  )
}
</code></pre>

<p>But I have doubts about it. For example it is hard to occasionally "catch" specific RuntimeExceptions with this solution. Perhaps there is a well known way to deal with situation that I just don't know how to google?</p>