我不太清楚如何使用addGlobalErrorListener(EasyThread.ErrorListener err)
。
让我们进入addGlobalErrorListener(EasyThread.ErrorListener err)
中的代码:
init()
测试EDT的代码:
// Pro only feature (disabled)
Log.bindCrashProtection(false);
// Custom EDT error handling
CN.addEdtErrorHandler(e -> {
Log.p("\n\n--- EDT CRASH REPORT ---\n", Log.ERROR);
Log.e((Throwable) e.getSource());
Server.sendLogAsync();
Dialog.show("EDT Exception", "Please be patient, report the following ERROR to the developers and then kill the app:\n\n" + e.getSource().toString(), null, null);
});
// Custom EasyThread error handling
EasyThread.addGlobalErrorListener((t, c, e) -> {
CN.callSerially(() -> {
Log.p("\n\n--- Easy Thread CRASH REPORT ---\n", Log.ERROR);
Log.p("Thead name: " + Thread.currentThread().getName());
Log.e(e);
Server.sendLogAsync();
Dialog.show("EDT Exception", "Please be patient, report the following ERROR to the developers and then kill the app:\n\n" + e.getMessage(), null, null);
});
});
测试EasyThread的代码:
CN.callSerially(() -> {
throw new IllegalStateException("Example of IllegalStateException in EDT");
})
您可以猜到,thread.run(() -> {
throw new IllegalStateException("Example of IllegalStateException in EasyThread");
});
是我自己对Server.sendLogAsync()
的实现。此外,我禁用了崩溃保护功能,因为当发生非托管异常时,我想强制测试人员终止该应用程序。
我的问题:
此代码正确吗?我注意到,除了在Android和iOS上,它的工作方式与我相同,但是当在EasyThead中引发异常时,模拟器变得无响应。此外,当处理EasyThread异常时,模拟器不会显示对话框,而Android和iOS会显示该对话框。
Log.sendLogAsync()
和EasyThread t
作为<T> callback
的onError(EasyThread t, T callback, Throwable error)
方法的参数有什么用?在这种情况下,EasyThread.ErrorListener<T>
是什么?
感谢您的澄清
线程名称在处理代码中不正确,您应该始终将EDT打印出来:
T
模拟器错误很奇怪,我非常想知道在这种情况下会发生什么。如果在调试器中可重现,则可能应该易于跟踪。
// Custom EasyThread error handling
EasyThread.addGlobalErrorListener((t, c, e) -> {
String threadName = Thread.currentThread().getName();
CN.callSerially(() -> {
Log.p("\n\n--- Easy Thread CRASH REPORT ---\n", Log.ERROR);
Log.p("Thead name: " + threadName);
if(e != null) {
Log.e(e);
}
Server.sendLogAsync();
Dialog.show("EDT Exception", "Please be patient, report the following ERROR to the developers and then kill the app:\n\n" + e.getMessage(), null, null);
});
});
为您直接引用了触发错误的线程池。
回调实质上是我们正在运行的EasyThread
或类似接口,例如Runnable
。因此,RunnableWithResult
表示接口的类型。您可以将其设置为对象,以保持通用性。