diff --git a/src/main/java/rx/internal/schedulers/ScheduledAction.java b/src/main/java/rx/internal/schedulers/ScheduledAction.java index f9fe694400..1d04a95a7d 100644 --- a/src/main/java/rx/internal/schedulers/ScheduledAction.java +++ b/src/main/java/rx/internal/schedulers/ScheduledAction.java @@ -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 { @@ -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(); }