Skip to content

Commit 1807575

Browse files
Merge pull request #1746 from benjchristensen/issue-1682
Fatal System.err Logs on Unhandled Exceptions
2 parents 8072871 + e27ff50 commit 1807575

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/main/java/rx/internal/schedulers/ScheduledAction.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
*/
1616
package rx.internal.schedulers;
1717

18+
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
19+
1820
import rx.Subscription;
21+
import rx.exceptions.OnErrorNotImplementedException;
1922
import rx.functions.Action0;
23+
import rx.plugins.RxJavaPlugins;
2024
import rx.subscriptions.CompositeSubscription;
2125

22-
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
23-
2426
/**
25-
* A {@code Runnable} that executes an {@code Action0} and can be cancelled. The analogue is the
27+
* A {@code Runnable} that executes an {@code Action0} and can be cancelled. The analog is the
2628
* {@code Subscriber} in respect of an {@code Observer}.
2729
*/
2830
public final class ScheduledAction implements Runnable, Subscription {
@@ -41,6 +43,16 @@ public ScheduledAction(Action0 action) {
4143
public void run() {
4244
try {
4345
action.call();
46+
} catch (Throwable e) {
47+
// nothing to do but print a System error as this is fatal and there is nowhere else to throw this
48+
IllegalStateException ie = null;
49+
if (e instanceof OnErrorNotImplementedException) {
50+
ie = new IllegalStateException("Exception thrown on Scheduler.Worker thread. Add `onError` handling.", e);
51+
} else {
52+
ie = new IllegalStateException("Fatal Exception thrown on Scheduler.Worker thread.", e);
53+
}
54+
ie.printStackTrace();
55+
RxJavaPlugins.getInstance().getErrorHandler().handleError(ie);
4456
} finally {
4557
unsubscribe();
4658
}

0 commit comments

Comments
 (0)