0

I am getting:

io.reactivex.exceptions.OnErrorNotImplementedException: The exception was not handled due to missing onError handler in the subscribe() method call

I had tried to add

.doOnError { error ->
            Log.i("reverser code error",error.localizedMessage)
       }.onErrorReturn { err ->
          "Return method"
     }

But it's not working.

Muhammad Farhan
  • 1,113
  • 10
  • 22
Sandip
  • 43
  • 1
  • 6

1 Answers1

0

doOnError and other Side Effect operators do not affect your stream in itself. Instead they are invoked when certain events occur to allow you to react to those events, in another words they just anticipate the values emitted for side-effect operations like logging for example

You can pass another lambda to subscribe to handle the errors for a specific stream like this:

.subscribe( { /*on subscribe method here*/}, { throwable -> /*handle error*/ } )

Take a look at this tutorial -> https://www.grokkingandroid.com/rxjavas-side-effect-methods/

  • when i put { throwable -> /*handle error*/ } on subscribe its not returning when it return data. – Sandip Feb 17 '20 at 08:41
  • That's because the second lambda will be only invoke when an error occurs :) – Oscar Emilio Perez Martinez Feb 17 '20 at 16:42
  • i am using this code. fun Observable.observe(block: (T) -> Unit) = this .observeOn(AndroidSchedulers.mainThread()) .subscribe({block},{throw IOException()}).apply { compositeDisposable.add(this) } block code is not execute when data is return – Sandip Feb 19 '20 at 04:15