Skip to content

Instantly share code, notes, and snippets.

@liminal
Last active April 3, 2018 09:17
Show Gist options
  • Save liminal/c6035ab54c61c642ceb019dc16e0fcec to your computer and use it in GitHub Desktop.
Save liminal/c6035ab54c61c642ceb019dc16e0fcec to your computer and use it in GitHub Desktop.
[Reasonable app error-handling for RxJava2] #android #rx
RxJavaPlugins.setErrorHandler(
{ err ->
var e = err
if (e is UndeliverableException) {
e = e.cause
}
when (e) {
is IOException, is SocketException -> return@setErrorHandler // fine, irrelevant network problem or API that throws on cancellation
is InterruptedException -> return@setErrorHandler // fine, some blocking code was interrupted by a dispose call
is NullPointerException, is IllegalArgumentException -> {
// that's likely a bug in the application
Thread.currentThread().uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), e)
return@setErrorHandler
}
is IllegalStateException -> {
// that's a bug in RxJava or in a custom operator
Thread.currentThread().uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), e)
return@setErrorHandler
}
else -> Timber.w(e, "Undeliverable exception received, not sure what to do")
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment