RxJava 全局处理程序和 Android Vitals



我对RxJava全局处理程序和Android Vitals有疑问。 在 Android Vitals 中,我可以看到

io.reactivex.exceptions.UndeliveryableException

原因:java.lang.InterruptedException: at com.google.common.util.concurrent.AbstractFuture.get (AbstractFuture.java:527( at com.google.common.util.concurrent.FluentFuture$TrustedFuture.get (流利未来.java:82(

但是我已经不知道问题出在哪里,所以我考虑添加 RxJava 全局错误处理程序:

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);
});

这是我的问题。如果我要添加全局错误处理程序,我将丢失来自 Android 指标的报告?丢失的意思是不会有新的报告,以防我们将处理导致崩溃的错误。

是否可以添加全局错误处理程序并仍然在 Android 指标中获取报告?

你的目标应该是减少崩溃。因此,只要您能够正确处理异常,就应该这样做。

当异常无法传递给观察者时,通常会弹出UndeliverableException。当一个没有观察员的Subject时,这可能是一种情况。

通常,您可以轻松解决这些问题。或者您可以忽略它并重新抛出任何其他错误。

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

也许还可以记录问题以注意它。

最新更新