Codenameone 代码名One EasyThread.addGlobalErrorListener用法

Codenameone 代码名One EasyThread.addGlobalErrorListener用法,codenameone,Codenameone,我不知道该怎么用 让我们转到init()中的我的代码: 测试EDT的代码: CN.callSerially(() -> { throw new IllegalStateException("Example of IllegalStateException in EDT"); }) 要测试EasyThread的代码: thread.run(() -> { throw new IllegalStateException("

我不知道该怎么用

让我们转到
init()
中的我的代码:

测试EDT的代码:

CN.callSerially(() -> {
            throw new IllegalStateException("Example of IllegalStateException in EDT");
        })
要测试EasyThread的代码:

thread.run(() -> {
            throw new IllegalStateException("Example of IllegalStateException in EasyThread");
        });
您可以猜到,
Server.sendLogAsync()
是我自己的
Log.sendLogAsync()
实现。此外,我禁用了崩溃保护,因为我想在发生非托管异常时强制测试人员终止应用程序

我的问题是:

  • 这个代码正确吗?我注意到,除了在Android和iOS上,它和我一样工作,但当抛出EasyHead中的异常时,模拟器就会失去响应。此外,当处理EasyThread异常时,模拟器不会显示对话框,而Android和iOS会显示对话框

  • EasyThread t
    callback
    作为
    EasyThread.ErrorListener
    的方法
    onError(EasyThread t,t callback,Throwable error)
    的参数有什么用途?在这种情况下,
    T
    是什么


  • 感谢您的澄清

    处理代码中的线程名称不正确,您应该始终打印出EDT:

        // 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
      。因此
      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);
            });
        });