Skip to content

Commit fe9badc

Browse files
committed
Merge pull request #3626 from davidmoten/simplify-throw
use Exceptions.throwOrError to simplify error handling
2 parents 90df5da + 25f7667 commit fe9badc

File tree

8 files changed

+13
-27
lines changed

8 files changed

+13
-27
lines changed

src/main/java/rx/Single.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,15 @@ public void call(Subscriber<? super R> o) {
185185
st.onStart();
186186
onSubscribe.call(st);
187187
} catch (Throwable e) {
188-
Exceptions.throwIfFatal(e);
189188
// localized capture of errors rather than it skipping all operators
190189
// and ending up in the try/catch of the subscribe method which then
191190
// prevents onErrorResumeNext and other similar approaches to error handling
192-
st.onError(e);
191+
Exceptions.throwOrReport(e, st);
193192
}
194193
} catch (Throwable e) {
195-
Exceptions.throwIfFatal(e);
196194
// if the lift function failed all we can do is pass the error to the final Subscriber
197195
// as we don't have the operator available to us
198-
o.onError(e);
196+
Exceptions.throwOrReport(e, o);
199197
}
200198
}
201199
});

src/main/java/rx/internal/operators/OnSubscribeFromCallable.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ public void call(Subscriber<? super T> subscriber) {
3131
try {
3232
singleDelayedProducer.setValue(resultFactory.call());
3333
} catch (Throwable t) {
34-
Exceptions.throwIfFatal(t);
35-
subscriber.onError(t);
34+
Exceptions.throwOrReport(t, subscriber);
3635
}
3736
}
3837
}

src/main/java/rx/internal/operators/OperatorScan.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ public void onNext(T t) {
108108
try {
109109
v = accumulator.call(v, t);
110110
} catch (Throwable e) {
111-
Exceptions.throwIfFatal(e);
112-
child.onError(OnErrorThrowable.addValueAsLastCause(e, t));
111+
Exceptions.throwOrReport(e, child, t);
113112
return;
114113
}
115114
}
@@ -138,8 +137,7 @@ public void onNext(T currentValue) {
138137
try {
139138
v = accumulator.call(v, currentValue);
140139
} catch (Throwable e) {
141-
Exceptions.throwIfFatal(e);
142-
onError(OnErrorThrowable.addValueAsLastCause(e, currentValue));
140+
Exceptions.throwOrReport(e, this, currentValue);
143141
return;
144142
}
145143
value = v;
@@ -322,8 +320,7 @@ void emitLoop() {
322320
try {
323321
child.onNext(v);
324322
} catch (Throwable ex) {
325-
Exceptions.throwIfFatal(ex);
326-
child.onError(OnErrorThrowable.addValueAsLastCause(ex, v));
323+
Exceptions.throwOrReport(ex, child, v);
327324
return;
328325
}
329326
r--;

src/main/java/rx/internal/operators/OperatorToMap.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ public Subscriber<? super T> call(final Subscriber<? super Map<K, V>> subscriber
8383
try {
8484
localMap = mapFactory.call();
8585
} catch (Throwable ex) {
86-
Exceptions.throwIfFatal(ex);
87-
subscriber.onError(ex);
86+
Exceptions.throwOrReport(ex, subscriber);
8887
Subscriber<? super T> parent = Subscribers.empty();
8988
parent.unsubscribe();
9089
return parent;
@@ -110,8 +109,7 @@ public void onNext(T v) {
110109
key = keySelector.call(v);
111110
value = valueSelector.call(v);
112111
} catch (Throwable ex) {
113-
Exceptions.throwIfFatal(ex);
114-
subscriber.onError(ex);
112+
Exceptions.throwOrReport(ex, subscriber);
115113
return;
116114
}
117115

src/main/java/rx/internal/operators/OperatorToMultimap.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ public void onNext(T v) {
138138
key = keySelector.call(v);
139139
value = valueSelector.call(v);
140140
} catch (Throwable ex) {
141-
Exceptions.throwIfFatal(ex);
142-
subscriber.onError(ex);
141+
Exceptions.throwOrReport(ex, subscriber);
143142
return;
144143
}
145144

@@ -148,8 +147,7 @@ public void onNext(T v) {
148147
try {
149148
collection = collectionFactory.call(key);
150149
} catch (Throwable ex) {
151-
Exceptions.throwIfFatal(ex);
152-
subscriber.onError(ex);
150+
Exceptions.throwOrReport(ex, subscriber);
153151
return;
154152
}
155153
map.put(key, collection);

src/main/java/rx/internal/operators/UnicastSubject.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ public void onNext(T t) {
154154
try {
155155
s.onNext(t);
156156
} catch (Throwable ex) {
157-
Exceptions.throwIfFatal(ex);
158-
s.onError(OnErrorThrowable.addValueAsLastCause(ex, t));
157+
Exceptions.throwOrReport(ex, s, t);
159158
}
160159
}
161160
}

src/main/java/rx/observers/SafeSubscriber.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ public void onNext(T args) {
141141
} catch (Throwable e) {
142142
// we handle here instead of another method so we don't add stacks to the frame
143143
// which can prevent it from being able to handle StackOverflow
144-
Exceptions.throwIfFatal(e);
145-
// handle errors if the onNext implementation fails, not just if the Observable fails
146-
onError(e);
144+
Exceptions.throwOrReport(e, this);
147145
}
148146
}
149147

src/main/java/rx/observers/SerializedObserver.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ public void onNext(T t) {
9595
actual.onNext(t);
9696
} catch (Throwable e) {
9797
terminated = true;
98-
Exceptions.throwIfFatal(e);
99-
actual.onError(OnErrorThrowable.addValueAsLastCause(e, t));
98+
Exceptions.throwOrReport(e, actual, t);
10099
return;
101100
}
102101
for (;;) {

0 commit comments

Comments
 (0)