I would like to know how to ignore exceptions and continue infinite stream (in my case stream of locations)?
I\'m fetching current user position (using Android-React
Just pasting the link info from @MikeN's answer incase it gets lost:
import rx.Observable.Operator;
import rx.functions.Action1;
public final class OperatorSuppressError implements Operator {
final Action1 onError;
public OperatorSuppressError(Action1 onError) {
this.onError = onError;
}
@Override
public Subscriber super T> call(final Subscriber super T> t1) {
return new Subscriber(t1) {
@Override
public void onNext(T t) {
t1.onNext(t);
}
@Override
public void onError(Throwable e) {
onError.call(e);
}
@Override
public void onCompleted() {
t1.onCompleted();
}
};
}
}
and use it close to the observable source because other operators may eagerly unsubscribe before that.
Observerable.create(connectToUnboundedStream()).lift(new OperatorSuppressError(log()).doOnNext(someStuff()).subscribe();
Note, however, that this suppresses the error delivery from the source. If any onNext in the chain after it throws an exception, it is still likely the source will be unsubscribed.