|
39 | 39 | import rx.observables.BlockingObservable;
|
40 | 40 | import rx.observables.ConnectableObservable;
|
41 | 41 | import rx.observables.GroupedObservable;
|
| 42 | +import rx.operators.OperationOnExceptionResumeNextViaObservable; |
42 | 43 | import rx.operators.SafeObservableSubscription;
|
43 | 44 | import rx.operators.SafeObserver;
|
44 | 45 | import rx.operators.OperationAll;
|
@@ -1869,6 +1870,36 @@ public static <T> Observable<T> onErrorResumeNext(final Observable<T> that, fina
|
1869 | 1870 | public static <T> Observable<T> onErrorReturn(final Observable<T> that, Func1<Throwable, T> resumeFunction) {
|
1870 | 1871 | return create(OperationOnErrorReturn.onErrorReturn(that, resumeFunction));
|
1871 | 1872 | }
|
| 1873 | + |
| 1874 | + /** |
| 1875 | + * Instruct an Observable to pass control to another Observable rather than invoking {@link Observer#onError onError} if it encounters an error of type {@link java.lang.Exception}. |
| 1876 | + * <p> |
| 1877 | + * This differs from {@link #onErrorResumeNext} in that this one does not handle {@link java.lang.Throwable} or {@link java.lang.Error} but lets those continue through. |
| 1878 | + * <p> |
| 1879 | + * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/onErrorResumeNext.png"> |
| 1880 | + * <p> |
| 1881 | + * By default, when an Observable encounters an error that prevents it from emitting the |
| 1882 | + * expected item to its Observer, the Observable invokes its {@link Observer}'s {@code onError} method, and then quits without invoking any more of its Observer's |
| 1883 | + * methods. The {@code onErrorResumeNext} method changes this behavior. If you pass an |
| 1884 | + * Observable ({@code resumeSequence}) to {@code onErrorResumeNext}, if the original |
| 1885 | + * Observable encounters an error, instead of invoking its Observer's <code>onError</code> |
| 1886 | + * method, it will instead relinquish control to this new Observable, which will invoke the |
| 1887 | + * Observer's {@link Observer#onNext onNext} method if it is able to do so. In such a case, |
| 1888 | + * because no Observable necessarily invokes {@code onError}, the Observer may never know |
| 1889 | + * that an error happened. |
| 1890 | + * <p> |
| 1891 | + * You can use this to prevent errors from propagating or to supply fallback data should errors |
| 1892 | + * be encountered. |
| 1893 | + * |
| 1894 | + * @param that |
| 1895 | + * the source Observable |
| 1896 | + * @param resumeSequence |
| 1897 | + * a Observable that will take over if the source Observable encounters an error |
| 1898 | + * @return an Observable, identical to the source Observable with its behavior modified as described |
| 1899 | + */ |
| 1900 | + public static <T> Observable<T> onExceptionResumeNext(final Observable<T> that, final Observable<T> resumeSequence) { |
| 1901 | + return create(OperationOnExceptionResumeNextViaObservable.onExceptionResumeNextViaObservable(that, resumeSequence)); |
| 1902 | + } |
1872 | 1903 |
|
1873 | 1904 | /**
|
1874 | 1905 | * Returns a {@link ConnectableObservable} that shares a single subscription to the underlying
|
@@ -3640,6 +3671,38 @@ public Observable<T> call(Throwable e) {
|
3640 | 3671 | public Observable<T> onErrorResumeNext(final Observable<T> resumeSequence) {
|
3641 | 3672 | return onErrorResumeNext(this, resumeSequence);
|
3642 | 3673 | }
|
| 3674 | + |
| 3675 | + /** |
| 3676 | + * Instruct an Observable to pass control to another Observable rather than invoking |
| 3677 | + * {@link Observer#onError onError} if it encounters an error of type {@link java.lang.Exception}. |
| 3678 | + * <p> |
| 3679 | + * This differs from {@link #onErrorResumeNext} in that this one does not handle {@link java.lang.Throwable} or {@link java.lang.Error} but lets those continue through. |
| 3680 | + * <p> |
| 3681 | + * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/onErrorResumeNext.png"> |
| 3682 | + * <p> |
| 3683 | + * By default, when an Observable encounters an error that prevents it from emitting the |
| 3684 | + * expected item to its {@link Observer}, the Observable invokes its Observer's |
| 3685 | + * <code>onError</code> method, and then quits without invoking any more of its Observer's |
| 3686 | + * methods. The <code>onErrorResumeNext</code> method changes this behavior. If you pass |
| 3687 | + * another Observable (<code>resumeSequence</code>) to an Observable's |
| 3688 | + * <code>onErrorResumeNext</code> method, if the original Observable encounters an error, |
| 3689 | + * instead of invoking its Observer's <code>onError</code> method, it will instead relinquish |
| 3690 | + * control to <code>resumeSequence</code> which will invoke the Observer's |
| 3691 | + * {@link Observer#onNext onNext} method if it is able to do so. In such a case, because no |
| 3692 | + * Observable necessarily invokes <code>onError</code>, the Observer may never know that an |
| 3693 | + * error happened. |
| 3694 | + * <p> |
| 3695 | + * You can use this to prevent errors from propagating or to supply fallback data should errors |
| 3696 | + * be encountered. |
| 3697 | + * |
| 3698 | + * @param resumeSequence |
| 3699 | + * a function that returns an Observable that will take over if the source Observable |
| 3700 | + * encounters an error |
| 3701 | + * @return the original Observable, with appropriately modified behavior |
| 3702 | + */ |
| 3703 | + public Observable<T> onExceptionResumeNext(final Observable<T> resumeSequence) { |
| 3704 | + return onExceptionResumeNext(this, resumeSequence); |
| 3705 | + } |
3643 | 3706 |
|
3644 | 3707 | /**
|
3645 | 3708 | * Instruct an Observable to emit an item (returned by a specified function) rather than
|
|
0 commit comments