MiraiForum

    • Register
    • Login
    • Search
    • Popular
    • Recent
    • Unsolved
    • Tags
    • Groups
    • 友情链接

    Solved java中 SimpleListenerHost.handleException函数并没有被执行

    开发交流
    2
    7
    154
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • HollisMeynell
      HollisMeynell last edited by

      萌新提问,大概是示例中

      public class MyEventHandlers extends SimpleListenerHost {
          @Override
          public void handleException(@NotNull CoroutineContext context, @NotNull Throwable exception){
              // 处理事件处理时抛出的异常
          }
         ...
      }
      

      但是在项目中并不会被实现

      @Override
          public void handleException(@NotNull CoroutineContext context, @NotNull Throwable exception){
      //不会被执行
              System.exit(0);
      //程序继续运行,log文件也正常输出test错误
          }
      
      
          @Async
          @EventHandler
          public void msg(MessageEvent event) throws Throwable{
                  throw new RuntimeException(
                          "test"
                  );
          }
      

      请问我应该怎么修改

      1 Reply Last reply Reply Quote 0
      • HollisMeynell
        HollisMeynell last edited by

        @EventHandler监听是工作正常的,此类继承于SimpleListenerHost,但是监听类交由ioc容器管理,是否与此有关

        1 Reply Last reply Reply Quote 0
        • Karlatemp
          Karlatemp last edited by

          Please open a new issue on github

          1 Reply Last reply Reply Quote 0
          • Karlatemp
            Karlatemp last edited by

            https://github.com/mamoe/mirai/pull/1490

            Karlatemp created this issue in mamoe/mirai

            closed Ensure `SimpleListenerHost.handleException` is called; Cancel registered listeners in `SimpleListenerHost` when it's completed #1490

            HollisMeynell 1 Reply Last reply Reply Quote 0
            • HollisMeynell
              HollisMeynell @Karlatemp last edited by

              @karlatemp 感谢,辛苦了

              1 Reply Last reply Reply Quote 0
              • Karlatemp
                Karlatemp last edited by

                目前可以使用

                EventChannel#parentScope(listener).registerListenerHost(lister)
                

                来解决问题

                HollisMeynell 1 Reply Last reply Reply Quote 0
                • HollisMeynell
                  HollisMeynell @Karlatemp last edited by

                  灰常感谢,可不可以另外请教一个问题,就是handleException的两个参数,第一个参数CoroutineContext可不可以获得抛出错误线程/方法持有的Event,用于取得发送者并回复错误信息
                  目前我是自定义异常,然后在这里面放入了上下文的数据(event对象)

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post
                  Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact