How to ignore error and continue infinite stream?

onerrorresumenext rxjava
rxjs catch error and continue
observable ignore error
rxjava retry
rxjava retrywhen example
rxjs ignore error

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-ReactiveLocation) and then sending them to my API (using Retrofit).

In my case, when exception occurs during network call (e.g. timeout) onError method is invoked and stream stops itself. How to avoid it?


private RestService mRestService;
private Subscription mSubscription;
private LocationRequest mLocationRequest = LocationRequest.create()
private void start() {
    mRestService = ...;
    ReactiveLocationProvider reactiveLocationProvider = new ReactiveLocationProvider(this);
    mSubscription = reactiveLocationProvider.getUpdatedLocation(mLocationRequest)
            .flatMap(locations -> mRestService.postLocations(locations)) // can throw exception


public interface RestService {
    Observable<Response> postLocations(@Body List<Location> locations);

mRestService.postLocations(locations) emit one item, then complete. If an error occur, then it emit the error, which complete the stream.

As you call this method in a flatMap, the error continue to your "main" stream, and then your stream stops.

What you can do is to transform your error into another item (as described here : ), but not on your main stream (as I presume you already tried) but on the mRestService.postLocations(locations).

This way, this call will emit an error, that will be transformed to an item/another observable and then complete. (without calling onError).

On a consumer view, mRestService.postLocations(locations) will emit one item, then complete, like if everything succeed.

mSubscription = reactiveLocationProvider.getUpdatedLocation(mLocationRequest)
        .flatMap(locations -> mRestService.postLocations(locations).onErrorReturn((e) -> Collections.emptyList()) // can't throw exception

RxJava question, Error handling could be complicated at an enterprise application. how RxJava propagates the error and terminates the reactive stream. We should be careful because it is possible to be trapped in an infinite loop in these� I saw your message, and I checked the link. You wrote "When I add onExceptionResumeNext(Observable.empty()) after the flatMap(locations -> mRestService.postLocations(locations)) onCompleted is invoked and stream ends. " It ends because Observable.empty() leads to onCompleted() as there are no values from Observable.empty() to emit.

RxJava — Handling Errors Like a Pro | by TC Wang, What I need here is not a retry, it's getting the error reach the Observers and errors down to the subscribers and have the observable continue emitting. Take a simple stream of click events that you flatMap to a stream of� Modifies the stream object. Concurrent access to the same stream object may cause data races, except for the standard stream object cin when this is synchronized with stdio (in this case, no data races are initiated, although no guarantees are given on the order in which extracted characters are attributed to threads). Exception safety

If you just want to ignore the error inside the flatMap without returning an element do this:

flatMap(item -> 

Error Handling Operators, See how to deal with errors using RxJava. sequence with default results, or simply leave it be so that the error could propagate. By using retry, the Observable will be re-subscribed infinite times until when there's no error. switches than -err_detect ignore_err to use to help ffmpeg ignore live stream errors while hls stream transcoding on the fly. The command I use is; ffmpeg -i "myvideo.mp4" -err_detect ignore_err -c:a aac -ar 48000 -ab 64k

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<T> implements Operator<T, T> {
    final Action1<Throwable> onError;

    public OperatorSuppressError(Action1<Throwable> onError) {
        this.onError = onError;

    public Subscriber<? super T> call(final Subscriber<? super T> t1) {
        return new Subscriber<T>(t1) {

            public void onNext(T t) {

            public void onError(Throwable e) {

            public void 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.

How to keep an Observable alive after onError? � Issue #3870 , Just like a catch in SEH (Structured Exception Handling), with Rx you have the Catch allows you to intercept a specific Exception type and then continue with another sequence. Here S1 represents the first sequence that ends with an error (X). Proper care should be taken when using the infinite repeat overload. To make LabVIEW ignore a specific error, you can use the General Error Handler VI or the Clear Error VI. The General Error Handler VI is located in the Programming » Dialog & User Interface palette. Right-click on the terminal [exception action] and create a constant. Set that constant to cancel error on match.

Try calling the rest service in a Observable.defer call. That way for every call you'll get a chance to use its own 'onErrorResumeNext' and the errors won't cause your main stream to complete.

  .flatMap(locations ->
    Observable.defer(() -> mRestService.postLocations(locations))

That solution is originally from this thread -> RxJava Observable and Subscriber for skipping exception?, but I think it will work in your case too.

RxJava and Error Handling, For example, we might want to do the following: swallow the error and switch over to a backup Observable to continue the sequence; swallow the error and emit a� Streamsmart review from Lake Havasu City, Arizona with 87 Comments: Own three Pro boxes and decided to give it a shot vs. new stuff. Ordered through on Thanksgiving eve and programs to load were waiting for me in the morning to do the upgrade.

Advanced error handling, In this post we'll go over using the observer's error callback as well as Otherwise if the stream continues failing you'll create an infinite loop. Java Stream API examples to generate infinite stream of data/elements. We will use Stream.generate() and Stream.iterate() methods to get the infinite streams.. Creating infinite streams is intermediate operation, so the elements creation doesn’t begin until the terminal operation of the pipeline is executed.

Error Handling With Observable Sequences, I do it all the time with things like conversion errors in D: to do something like this, you should be careful to only catch the specific exception you want to ignore. Restarting a package in the middle of a data flow execution is possible, but it takes some extra design measures. You’d need to use a lookup (either in the data flow or a JOIN in the database engine) to reprocess the data, skipping rows that have already been processed.

Simple Error Handling in RxJS, To get the idea about ignore() is working, we have to see one problem, and its solution is found using the ignore() function. The problem is like below. Sometimes we need to clear the unwanted buffer, so when next input is taken, it stores into the desired container, but not in the buffer of previous variable.

  • see the similar answer with click events exceptions:…
  • lol overly complicated setup of the question. You could have reduced this one to a few lines; ignoring project-specific semantics.
  • unfortunately it is not ignore, but emit empty list. it would be nice do not emit on error
  • What do you mean by // can throw exception? Does it mean even inside the onErrorReturn we might have an exception again?!
  • I think it's a mistake and it would be instead : "can't throw exception" (so I just edit the comment.) Nice catch!
  • When I add onExceptionResumeNext(Observable.empty()) after the flatMap(locations -> mRestService.postLocations(locations)) onCompleted is invoked and stream ends.
  • Don't add it after the flatMap, but inside the flatMap.
  • Thanks! onErrorResumeNext( ) - very usefull construction for fallbacks.
  • This works but after an error is suppressed my source observable seems to stop working. Is there a way to restart it?
  • @Matthias so this doesn't fix the problem? (Same as with onErrorResumeNext - it completes the observable)?
  • What does the materialize operator?