From e27ff503e223d8113282d9c5bd1806914e25fbcb Mon Sep 17 00:00:00 2001 From: Ben Christensen Date: Thu, 9 Oct 2014 22:41:46 -0700 Subject: [PATCH] Fatal System.err Logs on Unhandled Exceptions If an exception is thrown on a thread then we can't do anything with it so will log out to System.err. Fixes https://github.com/ReactiveX/RxJava/issues/1682 ScheduledAction Swallows Errors --- .../internal/schedulers/ScheduledAction.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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(); }