Skip to content

Commit

Permalink
Merge pull request #1746 from benjchristensen/issue-1682
Browse files Browse the repository at this point in the history
Fatal System.err Logs on Unhandled Exceptions
  • Loading branch information
benjchristensen committed Oct 10, 2014
2 parents 8072871 + e27ff50 commit 1807575
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/main/java/rx/internal/schedulers/ScheduledAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
*/
package rx.internal.schedulers;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

import rx.Subscription;
import rx.exceptions.OnErrorNotImplementedException;
import rx.functions.Action0;
import rx.plugins.RxJavaPlugins;
import rx.subscriptions.CompositeSubscription;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

/**
* A {@code Runnable} that executes an {@code Action0} and can be cancelled. The analogue is the
* A {@code Runnable} that executes an {@code Action0} and can be cancelled. The analog is the
* {@code Subscriber} in respect of an {@code Observer}.
*/
public final class ScheduledAction implements Runnable, Subscription {
Expand All @@ -41,6 +43,16 @@ public ScheduledAction(Action0 action) {
public void run() {
try {
action.call();
} catch (Throwable e) {
// nothing to do but print a System error as this is fatal and there is nowhere else to throw this
IllegalStateException ie = null;
if (e instanceof OnErrorNotImplementedException) {
ie = new IllegalStateException("Exception thrown on Scheduler.Worker thread. Add `onError` handling.", e);
} else {
ie = new IllegalStateException("Fatal Exception thrown on Scheduler.Worker thread.", e);
}
ie.printStackTrace();
RxJavaPlugins.getInstance().getErrorHandler().handleError(ie);
} finally {
unsubscribe();
}
Expand Down

0 comments on commit 1807575

Please sign in to comment.