Skip to content

Commit c196715

Browse files
add try/catch in example to better demonstrate error handling
… despite no errors being possible of being thrown in this code
1 parent 879a04c commit c196715

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

language-adaptors/rxjava-groovy/src/examples/groovy/rx/lang/groovy/examples/VideoExample.groovy

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,27 @@ Observable getVideoGridForDisplay(userId) {
108108
Observable<VideoList> getListOfLists(userId) {
109109
return Observable.create({ observer ->
110110
BooleanSubscription subscription = new BooleanSubscription();
111-
// this will happen on a separate thread as it requires a network call
112-
executor.execute({
113-
// simulate network latency
114-
Thread.sleep(180);
115-
for(i in 0..15) {
116-
if(subscription.isUnsubscribed()) {
117-
break;
111+
try {
112+
// this will happen on a separate thread as it requires a network call
113+
executor.execute({
114+
// simulate network latency
115+
Thread.sleep(180);
116+
for(i in 0..15) {
117+
if(subscription.isUnsubscribed()) {
118+
break;
119+
}
120+
try {
121+
//println("****** emitting list: " + i)
122+
observer.onNext(new VideoList(i))
123+
}catch(Exception e) {
124+
observer.onError(e);
125+
}
118126
}
119-
//println("****** emitting list: " + i)
120-
observer.onNext(new VideoList(i))
121-
}
122-
observer.onCompleted();
123-
})
127+
observer.onCompleted();
128+
})
129+
}catch(Exception e) {
130+
observer.onError(e);
131+
}
124132
return subscription;
125133
})
126134
}

0 commit comments

Comments
 (0)