1

So imagining i am iterating over a list of something, with Observable::from and for each item i want to perform a series of operations, which can return an error each one. Im doing it with flatMap, and at the end i return the original item, and call toList.

The chained observables that perform a couple of operations for each item can return an Error, and i want to, in all of those cases, to terminate the entire stream and just call the final onError, before the subscribe call.

Is there any way of accomplish that?

EDIT: I know i can use onErrorResumeNext and keep the Observable.from iterations going, but i want to terminate the stream, which means, no more iterations will be done if an error is found, and i just want to terminate the stream and display an error in the final OnError call. Code:

 dbRepository.getAppAllHomeItems() .flatMap(Observable::from) .flatMap(homeItem -> knoxStandardSdk.wipeApplicationDataObs(homeItem.getApplicationPackageName())) .subscribeOn(Schedulers.computation()) .toList() .doOnError(throwable -> AppSnackbarUtils.showSnackBar((Activity)context, "Please Activate Licenses First!", AppSnackbarUtils.LENGTH_LONG)) .subscribe(); 
4
  • I thought this is the default behaviour? If on Observable emits an error the chain gets interrupted and the doOnError will be called? Am I wrong? Commented Dec 2, 2015 at 13:47
  • What you are describing is the default behavior. Are you observing differently? :-) Commented Dec 2, 2015 at 14:21
  • yes it is my bad. I made the wrong assumption for two reasons. First, calling onError isn't handling the error, and so the exception will still happen. I need to explicitly call subscribe( ... onError ... ...). And secondly, the cause of my error was an error thrown inside a catch block, and for some reason i failed to realise that. So ya that is the default behaviour Commented Dec 2, 2015 at 14:30
  • so @Christopher since you were the first, can you answer the question? I know this is weird but the answer is that it is the default behaviour, as long as i handle the error inside subscribe block. I can answer myself, but you were the first Commented Dec 2, 2015 at 14:32

1 Answer 1

0

Your described behaviour is the defaulf behaviour.

Nevertheless, you also should implement the onError-Method in your Subscriber.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.