Created
June 11, 2020 09:08
-
-
Save MathiasSeguy-Android2EE/c333c00200d4980b8ab34859ae44beb0 to your computer and use it in GitHub Desktop.
Markdium-Chapter 9: Observable's action operators
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Using the observableWithErrorSrc skip error items and return a bad day item instead of the error | |
* @return | |
*/ | |
public static Observable getObservableWithOnErrorReturnItem() { | |
//you can also return an empty Observable and then quit the Observable nicely | |
return observableWithErrorSrc | |
.onErrorReturnItem("Bad day"); | |
} | |
/** | |
* OutPut result: | |
* value emitted is Monday | |
* value emitted is Bad day | |
* onCompleteCalled | |
*/ | |
@Test | |
public void testObservableWithOnErrorReturnItem() { | |
Answer9_ObservableActions.getObservableWithOnErrorReturnItem() | |
.subscribe(it -> System.out.println("value emitted is " + it), | |
Throwable::printStackTrace, | |
() -> System.out.println("onCompleteCalled")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment