-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRxJavaErrorExam2.java
More file actions
28 lines (25 loc) · 872 Bytes
/
RxJavaErrorExam2.java
File metadata and controls
28 lines (25 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import rx.Observable;
import rx.Subscriber;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.functions.Func1;
public class RxJavaErrorExam2 {
public static void main(String[] args) {
Observable
.create((Observable.OnSubscribe<String>) subscriber -> {
log("subscribe");
subscriber.onNext("emit 1");
subscriber.onNext("emit 2");
subscriber.onError(new Throwable());
})
.onErrorReturn(throwable -> "return")
.subscribe(
s -> log("on next: " + s),
throwable -> log("error:" + throwable),
() -> log("completed")
);
}
public static void log(String message) {
System.out.println(message);
}
}