I'm RxJava newbie, and I've got following problem. Say I have sequence of items and on of items propagates error, I want to ignore it and to continue processing other items.
I have following snippet:
Observable.from(Arrays.asList("1", "2", "3"))
.map(x -> {
if (x.equals("2")) {
throw new NullPointerException();
}
return x + "-";
})
.onExceptionResumeNext(Observable.empty())
.subscribe(System.out::println);
I'm getting: 1-
But I want to get: 1- , 3-
How can I do that?
the trick is to wrap the value, which would be transformed somehow, into a new observable and flatmap over it as in the following example. Each value in the flatMap can now throw a exception and handle it value by value. Becuase the substream in flatMap consists only of one element, it does not matter if the observable will be closed after onError. I use RxJava2 as test-environment.