0

I have question about RxJava global handler and Android Vitals. In Android Vitals I can see

io.reactivex.exceptions.UndeliverableException

Caused by: java.lang.InterruptedException: at com.google.common.util.concurrent.AbstractFuture.get (AbstractFuture.java:527) at com.google.common.util.concurrent.FluentFuture$TrustedFuture.get (FluentFuture.java:82)

But already I don't know where is the problem so I thought about adding RxJava global error handler:

RxJavaPlugins.setErrorHandler(e -> {
    if (e instanceof UndeliverableException) {
        e = e.getCause();
    }
    if ((e instanceof IOException) || (e instanceof SocketException)) {
        // fine, irrelevant network problem or API that throws on cancellation
        return;
    }
    if (e instanceof InterruptedException) {
        // fine, some blocking code was interrupted by a dispose call
        return;
    }
    if ((e instanceof NullPointerException) || (e instanceof IllegalArgumentException)) {
        // that's likely a bug in the application
        Thread.currentThread().getUncaughtExceptionHandler()
            .handleException(Thread.currentThread(), e);
        return;
    }
    if (e instanceof IllegalStateException) {
        // that's a bug in RxJava or in a custom operator
        Thread.currentThread().getUncaughtExceptionHandler()
            .handleException(Thread.currentThread(), e);
        return;
    }
    Log.warning("Undeliverable exception received, not sure what to do", e);
});

And there is my question. If I will add global error handler I will lost reports from Android Vitals ? By lost I mean there will be no new reports becase we will handle the error which causing crash.

Is it possible to add global error handler and still get reports in Android Vitals ?

Esperanz0
  • 1,524
  • 13
  • 35

1 Answers1

0

Your goal should be to reduce crashes. So whenever you're able to handle exceptions properly, you should do it.

The UndeliverableException usually pops up, when an exception couldn't be deliverd to an observer. That could be a case when a Subject that has no observers.

Often you could easily fix these easily. Or you could just ignore it and rethrow any other error.

RxJavaPlugins.setErrorHandler(e -> {
    if (e instanceof UndeliverableException) {
        return;
    }
    throw e;
});

Maybe also log the issue to be aware of it.

tynn
  • 38,113
  • 8
  • 108
  • 143