Multiple errors in zip'ed observables with flatMap
See original GitHub issueWhile reading Error handling on wiki I realized that in a zip operator with a multiple network calls, it’s possible to receive a crash with an UndeliverableException. I tried to reproduce this behavior:
RxJava version: 2.2.0
Reproduce code:
@Test
public void testUncaughtException() throws InterruptedException {
Observable first = Observable.create(e -> {
System.out.println("first");
throw new HelperException("first exception");
});
Observable second = Observable.create(e -> {
System.out.println("second");
throw new HelperException("second exception");
});
List<Observable<?>> observableList = new ArrayList<>();
observableList.add(first);
observableList.add(second);
Observable.zip(observableList, objects -> "result")
.subscribeOn(Schedulers.io())
.subscribe(
System.out::println,
t -> {
System.out.println("exception caught!");
}
);
Thread.sleep(2000);
}
The output as expected:
first
exception caught!
second
io.reactivex.exceptions.UndeliverableException: ... HelperException: second exception ...
And the second test:
@Test
public void testUncaughtExceptionWithFlatMap() throws InterruptedException {
Observable testObservable = Observable.create(e -> e.onNext(""))
.flatMap((Function<Object, ObservableSource<?>>) o -> {
Observable first = Observable.create(e -> {
System.out.println("first");
throw new HelperException("first exception");
});
Observable second = Observable.create(e -> {
System.out.println("second");
throw new HelperException("second exception");
});
List<Observable<?>> observableList = new ArrayList<>();
observableList.add(first);
observableList.add(second);
return Observable.zip(observableList, objects -> "result");
});
testObservable
.subscribeOn(Schedulers.io())
.subscribe(
System.out::println,
t -> System.out.println("exception caught!")
);
Thread.sleep(2000);
}
And I expected an UndeliverableException too, but the output is:
first
exception caught!
Is this behavior correct? Why there is no UndeliverableException in the second test?
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Error handling for zipped observables - rx java - Stack Overflow
First of all, the right way to notify a Subscriber about an error is to call subscriber ... flatMap(permalink -> Observable.zip( Observable.
Read more >RxSwift/RxCocoa : Handling errors with multiple observables ...
I´ve been trying to find a good, elegant way to handle errors when chaining multiple observables that can throw errors.
Read more >RxJava — Handling Errors Like a Pro | by TC Wang - Medium
RxJava provides many different error handlers when an error is thrown inside of a stream. Two of the most basic but useful Observers...
Read more >monix.reactive.Observable
Given the source observable and another Observable , emits all of the items from the first of these Observables to emit an item...
Read more >4. Applying Reactive Programming to Existing Applications
We will spend much more time on error handling later in this book (see ... Remember that the zip() operator subscribes to two...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Correction. In both cases, you shouldn’t see any undeliverable exceptions. What happens is that
flatMap
issues a cancel when it detects the error which then stops the subscription to the second source. I’ll investigate this further.@akarnokd thanks for explanations!
i am currently using
onErrorResumeNext
to tweak that part. so, whenever error occurs in observable i return default value.