Skip to content

Instantly share code, notes, and snippets.

@pyeongho
Created January 15, 2020 01:05
Show Gist options
  • Save pyeongho/8a50d38c8957a070098b8ebb71ae8ccc to your computer and use it in GitHub Desktop.
Save pyeongho/8a50d38c8957a070098b8ebb71ae8ccc to your computer and use it in GitHub Desktop.
RxJavaPlugins.setErrorHandler { e ->
var error : Throwable? = e
if (error is UndeliverableException) {
error = e.cause
}
if (error is IOException || error is SocketException) {
// fine, irrelevant network problem or API that throws on cancellation
return@setErrorHandler
}
if (error is InterruptedException) {
// fine, some blocking code was interrupted by a dispose call
return@setErrorHandler
}
if (error is NullPointerException || error is IllegalArgumentException) {
// that's likely a bug in the application
Thread.currentThread().uncaughtExceptionHandler
.uncaughtException(Thread.currentThread(), error)
return@setErrorHandler
}
if (error is IllegalStateException) {
// that's a bug in RxJava or in a custom operator
Thread.currentThread().uncaughtExceptionHandler
.uncaughtException(Thread.currentThread(), error)
return@setErrorHandler
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment