Skip to content

Instantly share code, notes, and snippets.

@aanandshekharroy
Created February 12, 2018 17:04
Show Gist options
  • Save aanandshekharroy/cb5c0e11f6c39721c2dbb81d78364644 to your computer and use it in GitHub Desktop.
Save aanandshekharroy/cb5c0e11f6c39721c2dbb81d78364644 to your computer and use it in GitHub Desktop.
Observable.fromArray(1,2,3)
.doOnNext {
if(it==2){
throw (RuntimeException("Exception on 2"))
}
}
.onErrorReturn{
t: Throwable ->
if(t.message=="<something you want>"){
1 // Return a value based on error type
}else{
100 // Return another value based on different error type
}
}
.subscribeBy(
onNext = {
println(it)
},onError = {
println(it.message)
},onComplete = {
println("Complete")
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment