Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change onError(Exception) to onError(Throwable) - Issue #296 #315

Merged
14 changes: 7 additions & 7 deletions rxjava-core/src/main/java/rx/Notification.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class Notification<T> {

private final Kind kind;
private final Exception exception;
private final Throwable exception;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit s/exception/throwable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will commit change shortly, also changing hasException to hasThrowable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private final T value;

/**
Expand All @@ -44,7 +44,7 @@ public Notification(T value) {
* @param exception
* The exception passed to the onError notification.
*/
public Notification(Exception exception) {
public Notification(Throwable exception) {
this.exception = exception;
this.value = null;
this.kind = Kind.OnError;
Expand All @@ -62,9 +62,9 @@ public Notification() {
/**
* Retrieves the exception associated with an onError notification.
*
* @return The exception associated with an onError notification.
* @return Throwable associated with an onError notification.
*/
public Exception getException() {
public Throwable getThrowable() {
return exception;
}

Expand Down Expand Up @@ -126,7 +126,7 @@ public String toString() {
if (hasValue())
str.append(" ").append(getValue());
if (hasException())
str.append(" ").append(getException().getMessage());
str.append(" ").append(getThrowable().getMessage());
str.append("]");
return str.toString();
}
Expand All @@ -137,7 +137,7 @@ public int hashCode() {
if (hasValue())
hash = hash * 31 + getValue().hashCode();
if (hasException())
hash = hash * 31 + getException().hashCode();
hash = hash * 31 + getThrowable().hashCode();
return hash;
}

Expand All @@ -154,7 +154,7 @@ public boolean equals(Object obj) {
return false;
if (hasValue() && !getValue().equals(notification.getValue()))
return false;
if (hasException() && !getException().equals(notification.getException()))
if (hasException() && !getThrowable().equals(notification.getThrowable()))
return false;
return true;
}
Expand Down
139 changes: 101 additions & 38 deletions rxjava-core/src/main/java/rx/Observable.java

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rxjava-core/src/main/java/rx/Observer.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public interface Observer<T> {
*
* @param e
*/
public void onError(Exception e);
public void onError(Throwable e);

/**
* Provides the Observer with new data.
Expand Down
10 changes: 5 additions & 5 deletions rxjava-core/src/main/java/rx/observables/BlockingObservable.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ private Subscription protectivelyWrapAndSubscribe(Observer<T> o) {
* NOTE: This will block even if the Observable is asynchronous.
* <p>
* This is similar to {@link #subscribe(Observer)}, but it blocks. Because it blocks it does
* not need the {@link Observer#onCompleted()} or {@link Observer#onError(Exception)} methods.
* not need the {@link Observer#onCompleted()} or {@link Observer#onError(Throwable)} methods.
* <p>
* <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/B.forEach.png">
*
Expand All @@ -426,7 +426,7 @@ private Subscription protectivelyWrapAndSubscribe(Observer<T> o) {
*/
public void forEach(final Action1<T> onNext) {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Exception> exceptionFromOnError = new AtomicReference<Exception>();
final AtomicReference<Throwable> exceptionFromOnError = new AtomicReference<Throwable>();

/**
* Wrapping since raw functions provided by the user are being invoked.
Expand All @@ -440,7 +440,7 @@ public void onCompleted() {
}

@Override
public void onError(Exception e) {
public void onError(Throwable e) {
/*
* If we receive an onError event we set the reference on the outer thread
* so we can git it and throw after the latch.await().
Expand Down Expand Up @@ -483,7 +483,7 @@ public void onNext(T args) {
* NOTE: This will block even if the Observable is asynchronous.
* <p>
* This is similar to {@link #subscribe(Observer)}, but it blocks. Because it blocks it does
* not need the {@link Observer#onCompleted()} or {@link Observer#onError(Exception)} methods.
* not need the {@link Observer#onCompleted()} or {@link Observer#onError(Throwable)} methods.
* <p>
* <img width="640" src="https://github.com/Netflix/RxJava/wiki/images/rx-operators/B.forEach.png">
*
Expand Down Expand Up @@ -1026,7 +1026,7 @@ public void call(String t1) {
}
});
fail("we expect an exception to be thrown");
} catch (Exception e) {
} catch (Throwable e) {
// do nothing as we expect this
}
}
Expand Down
4 changes: 2 additions & 2 deletions rxjava-core/src/main/java/rx/operators/OperationAll.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void onCompleted() {
}

@Override
public void onError(Exception e) {
public void onError(Throwable e) {
underlying.onError(e);
}

Expand Down Expand Up @@ -139,7 +139,7 @@ public Boolean call(String s) {
@Test
@SuppressWarnings("unchecked")
public void testError() {
Exception error = new Exception();
Throwable error = new Throwable();
Observable<String> obs = Observable.error(error);

Observer<Boolean> observer = mock(Observer.class);
Expand Down
18 changes: 9 additions & 9 deletions rxjava-core/src/main/java/rx/operators/OperationBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public void onCompleted() {
}

@Override
public void onError(Exception e) {
public void onError(Throwable e) {
creator.stop();
buffers.emitAllBuffers();
observer.onError(e);
Expand Down Expand Up @@ -901,7 +901,7 @@ public Subscription call(Observer<String> observer) {
buffered.subscribe(observer);

Mockito.verify(observer, Mockito.never()).onNext(Mockito.anyListOf(String.class));
Mockito.verify(observer, Mockito.never()).onError(Mockito.any(Exception.class));
Mockito.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class));
Mockito.verify(observer, Mockito.times(1)).onCompleted();
}

Expand All @@ -927,7 +927,7 @@ public Subscription call(Observer<String> observer) {
inOrder.verify(observer, Mockito.times(1)).onNext(list("two", "three", "four"));
inOrder.verify(observer, Mockito.times(1)).onNext(list("three", "four", "five"));
inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyListOf(String.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Exception.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class));
inOrder.verify(observer, Mockito.never()).onCompleted();
}

Expand All @@ -953,7 +953,7 @@ public Subscription call(Observer<String> observer) {
inOrder.verify(observer, Mockito.times(1)).onNext(list("one", "two", "three"));
inOrder.verify(observer, Mockito.times(1)).onNext(list("four", "five"));
inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyListOf(String.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Exception.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class));
inOrder.verify(observer, Mockito.times(1)).onCompleted();
}

Expand All @@ -979,7 +979,7 @@ public Subscription call(Observer<String> observer) {
inOrder.verify(observer, Mockito.times(1)).onNext(list("one", "two"));
inOrder.verify(observer, Mockito.times(1)).onNext(list("four", "five"));
inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyListOf(String.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Exception.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class));
inOrder.verify(observer, Mockito.times(1)).onCompleted();
}

Expand Down Expand Up @@ -1011,7 +1011,7 @@ public Subscription call(Observer<String> observer) {
scheduler.advanceTimeTo(300, TimeUnit.MILLISECONDS);
inOrder.verify(observer, Mockito.times(1)).onNext(list("five"));
inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyListOf(String.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Exception.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class));
inOrder.verify(observer, Mockito.times(1)).onCompleted();
}

Expand Down Expand Up @@ -1040,7 +1040,7 @@ public Subscription call(Observer<String> observer) {
scheduler.advanceTimeTo(201, TimeUnit.MILLISECONDS);
inOrder.verify(observer, Mockito.times(1)).onNext(list("four", "five"));
inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyListOf(String.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Exception.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class));
inOrder.verify(observer, Mockito.times(1)).onCompleted();
}

Expand Down Expand Up @@ -1091,7 +1091,7 @@ public Subscription call(Observer<BufferClosing> observer) {
inOrder.verify(observer, Mockito.times(1)).onNext(list("two", "three"));
inOrder.verify(observer, Mockito.times(1)).onNext(list("five"));
inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyListOf(String.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Exception.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class));
inOrder.verify(observer, Mockito.times(1)).onCompleted();
}

Expand Down Expand Up @@ -1133,7 +1133,7 @@ public Subscription call(Observer<BufferClosing> observer) {
inOrder.verify(observer, Mockito.times(1)).onNext(list("three", "four"));
inOrder.verify(observer, Mockito.times(1)).onNext(list("five"));
inOrder.verify(observer, Mockito.never()).onNext(Mockito.anyListOf(String.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Exception.class));
inOrder.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class));
inOrder.verify(observer, Mockito.times(1)).onCompleted();
}

Expand Down
42 changes: 21 additions & 21 deletions rxjava-core/src/main/java/rx/operators/OperationCombineLatest.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void onCompleted() {
}

@Override
public void onError(Exception e) {
public void onError(Throwable e) {
a.error(e);
}

Expand Down Expand Up @@ -185,7 +185,7 @@ <T> void complete(CombineObserver<? extends R, ? super T> w) {
/**
* Receive error for a Observer. Throw the error up the chain and stop processing.
*/
void error(Exception e) {
void error(Throwable e) {
observer.onError(e);
/* tell all observers to unsubscribe since we had an error */
stop();
Expand Down Expand Up @@ -226,7 +226,7 @@ <T> void next(CombineObserver<? extends R, ? super T> w, T arg) {
try {
R combinedValue = combineLatestFunction.call(argsToCombineLatest);
observer.onNext(combinedValue);
} catch(Exception ex) {
} catch(Throwable ex) {
observer.onError(ex);
}
}
Expand Down Expand Up @@ -433,14 +433,14 @@ public void testAggregatorSimple() {

InOrder inOrder = inOrder(aObserver);

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, never()).onCompleted();
inOrder.verify(aObserver, times(1)).onNext("helloworld");

a.next(r1, "hello ");
a.next(r2, "again");

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, never()).onCompleted();
inOrder.verify(aObserver, times(1)).onNext("hello again");

Expand Down Expand Up @@ -476,14 +476,14 @@ public void testAggregatorDifferentSizedResultsWithOnComplete() {
a.next(r2, "world");
a.complete(r2);

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, never()).onCompleted();
verify(aObserver, times(1)).onNext("helloworld");

a.next(r1, "hi");
a.complete(r1);

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, times(1)).onCompleted();
verify(aObserver, times(1)).onNext("hiworld");
}
Expand Down Expand Up @@ -513,14 +513,14 @@ public void testAggregateMultipleTypes() {
a.next(r2, "world");
a.complete(r2);

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, never()).onCompleted();
verify(aObserver, times(1)).onNext("helloworld");

a.next(r1, "hi");
a.complete(r1);

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, times(1)).onCompleted();
verify(aObserver, times(1)).onNext("hiworld");
}
Expand Down Expand Up @@ -552,7 +552,7 @@ public void testAggregate3Types() {
a.next(r2, 2);
a.next(r3, new int[] { 5, 6, 7 });

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, never()).onCompleted();
verify(aObserver, times(1)).onNext("hello2[5, 6, 7]");
}
Expand Down Expand Up @@ -583,7 +583,7 @@ public void testAggregatorsWithDifferentSizesAndTiming() {
a.next(r1, "three");
a.next(r2, "A");

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, never()).onCompleted();
verify(aObserver, times(1)).onNext("threeA");

Expand All @@ -599,7 +599,7 @@ public void testAggregatorsWithDifferentSizesAndTiming() {
verify(aObserver, times(1)).onNext("fourE");
a.complete(r2);

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, times(1)).onCompleted();
}

Expand Down Expand Up @@ -627,15 +627,15 @@ public void testAggregatorError() {
a.next(r1, "hello");
a.next(r2, "world");

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, never()).onCompleted();
verify(aObserver, times(1)).onNext("helloworld");

a.error(new RuntimeException(""));
a.next(r1, "hello");
a.next(r2, "again");

verify(aObserver, times(1)).onError(any(Exception.class));
verify(aObserver, times(1)).onError(any(Throwable.class));
verify(aObserver, never()).onCompleted();
// we don't want to be called again after an error
verify(aObserver, times(0)).onNext("helloagain");
Expand Down Expand Up @@ -665,15 +665,15 @@ public void testAggregatorUnsubscribe() {
a.next(r1, "hello");
a.next(r2, "world");

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, never()).onCompleted();
verify(aObserver, times(1)).onNext("helloworld");

subscription.unsubscribe();
a.next(r1, "hello");
a.next(r2, "again");

verify(aObserver, times(0)).onError(any(Exception.class));
verify(aObserver, times(0)).onError(any(Throwable.class));
verify(aObserver, never()).onCompleted();
// we don't want to be called again after an error
verify(aObserver, times(0)).onNext("helloagain");
Expand Down Expand Up @@ -707,13 +707,13 @@ public void testAggregatorEarlyCompletion() {

InOrder inOrder = inOrder(aObserver);

inOrder.verify(aObserver, never()).onError(any(Exception.class));
inOrder.verify(aObserver, never()).onError(any(Throwable.class));
inOrder.verify(aObserver, never()).onCompleted();
inOrder.verify(aObserver, times(1)).onNext("twoA");

a.complete(r2);

inOrder.verify(aObserver, never()).onError(any(Exception.class));
inOrder.verify(aObserver, never()).onError(any(Throwable.class));
inOrder.verify(aObserver, times(1)).onCompleted();
// we shouldn't get this since completed is called before any other onNext calls could trigger this
inOrder.verify(aObserver, never()).onNext(anyString());
Expand All @@ -731,7 +731,7 @@ public void testCombineLatest2Types() {
Observable<String> w = Observable.create(combineLatest(Observable.from("one", "two"), Observable.from(2, 3, 4), combineLatestFunction));
w.subscribe(aObserver);

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, times(1)).onCompleted();
verify(aObserver, times(1)).onNext("two2");
verify(aObserver, times(1)).onNext("two3");
Expand All @@ -750,7 +750,7 @@ public void testCombineLatest3TypesA() {
Observable<String> w = Observable.create(combineLatest(Observable.from("one", "two"), Observable.from(2), Observable.from(new int[] { 4, 5, 6 }), combineLatestFunction));
w.subscribe(aObserver);

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, times(1)).onCompleted();
verify(aObserver, times(1)).onNext("two2[4, 5, 6]");
}
Expand All @@ -767,7 +767,7 @@ public void testCombineLatest3TypesB() {
Observable<String> w = Observable.create(combineLatest(Observable.from("one"), Observable.from(2), Observable.from(new int[] { 4, 5, 6 }, new int[] { 7, 8 }), combineLatestFunction));
w.subscribe(aObserver);

verify(aObserver, never()).onError(any(Exception.class));
verify(aObserver, never()).onError(any(Throwable.class));
verify(aObserver, times(1)).onCompleted();
verify(aObserver, times(1)).onNext("one2[4, 5, 6]");
verify(aObserver, times(1)).onNext("one2[7, 8]");
Expand Down
Loading