<bdo id='Oxfts'></bdo><ul id='Oxfts'></ul>
  • <tfoot id='Oxfts'></tfoot>

      1. <legend id='Oxfts'><style id='Oxfts'><dir id='Oxfts'><q id='Oxfts'></q></dir></style></legend>
      2. <i id='Oxfts'><tr id='Oxfts'><dt id='Oxfts'><q id='Oxfts'><span id='Oxfts'><b id='Oxfts'><form id='Oxfts'><ins id='Oxfts'></ins><ul id='Oxfts'></ul><sub id='Oxfts'></sub></form><legend id='Oxfts'></legend><bdo id='Oxfts'><pre id='Oxfts'><center id='Oxfts'></center></pre></bdo></b><th id='Oxfts'></th></span></q></dt></tr></i><div id='Oxfts'><tfoot id='Oxfts'></tfoot><dl id='Oxfts'><fieldset id='Oxfts'></fieldset></dl></div>

        <small id='Oxfts'></small><noframes id='Oxfts'>

        boost::asio::io_service::run() 抛出的异常是否应该被捕获?

        时间:2024-08-13

        <small id='URZgn'></small><noframes id='URZgn'>

        <tfoot id='URZgn'></tfoot><legend id='URZgn'><style id='URZgn'><dir id='URZgn'><q id='URZgn'></q></dir></style></legend>
          <tbody id='URZgn'></tbody>

            • <bdo id='URZgn'></bdo><ul id='URZgn'></ul>
              <i id='URZgn'><tr id='URZgn'><dt id='URZgn'><q id='URZgn'><span id='URZgn'><b id='URZgn'><form id='URZgn'><ins id='URZgn'></ins><ul id='URZgn'></ul><sub id='URZgn'></sub></form><legend id='URZgn'></legend><bdo id='URZgn'><pre id='URZgn'><center id='URZgn'></center></pre></bdo></b><th id='URZgn'></th></span></q></dt></tr></i><div id='URZgn'><tfoot id='URZgn'></tfoot><dl id='URZgn'><fieldset id='URZgn'></fieldset></dl></div>

                  本文介绍了boost::asio::io_service::run() 抛出的异常是否应该被捕获?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  boost::asio::io_service::run() 在发生错误时抛出 boost::system::system_error 异常.我应该处理这个异常吗?如果是,怎么办?

                  boost::asio::io_service::run() throws a boost::system::system_error exception in case of error. Should I handle this exception? If so, how?

                  我的 main.cpp 代码是这样的:

                  my main.cpp code is something like this:

                  main()
                  {
                      boost::asio::io_service queue;
                      boost::asio::io_service::work work(queue);
                      {
                        // set some handlers...
                        **queue.run();**
                      }
                      // join some workers...
                      return 0;
                  }
                  

                  推荐答案

                  是的.

                  据记载,完成处理程序抛出的异常会被传播.所以你需要根据你的应用来处理它们.

                  It is documented that exceptions thrown from completion handlers are propagated. So you need to handle them as appropriate for your application.

                  在许多情况下,这会循环并重复 run() 直到它没有错误地退出.

                  In many cases, this would be looping and repeating the run() until it exits without an error.

                  在我们的代码库中,我有类似的东西

                  In our code base I have something like

                  static void m_asio_event_loop(boost::asio::io_service& svc, std::string name) {
                      // http://www.boost.org/doc/libs/1_61_0/doc/html/boost_asio/reference/io_service.html#boost_asio.reference.io_service.effect_of_exceptions_thrown_from_handlers
                      for (;;) {
                          try {
                              svc.run();
                              break; // exited normally
                          } catch (std::exception const &e) {
                              logger.log(LOG_ERR) << "[eventloop] An unexpected error occurred running " << name << " task: " << e.what();
                          } catch (...) {
                              logger.log(LOG_ERR) << "[eventloop] An unexpected error occurred running " << name << " task";
                          }
                      }
                  }
                  

                  这里是文档链接 http://www.boost.org/doc/libs/1_61_0/doc/html/boost_asio/reference/io_service.html#boost_asio.reference.io_service.effect_of_exceptions_throw_from_handlers

                  这篇关于boost::asio::io_service::run() 抛出的异常是否应该被捕获?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:谁删除在“新"期间分配的内存?构造函数中有异常的操作? 下一篇:当没有抛出异常时,C++ 异常以什么方式减慢代码速度?

                  相关文章

                    <small id='CfBj0'></small><noframes id='CfBj0'>

                  1. <legend id='CfBj0'><style id='CfBj0'><dir id='CfBj0'><q id='CfBj0'></q></dir></style></legend>
                    <i id='CfBj0'><tr id='CfBj0'><dt id='CfBj0'><q id='CfBj0'><span id='CfBj0'><b id='CfBj0'><form id='CfBj0'><ins id='CfBj0'></ins><ul id='CfBj0'></ul><sub id='CfBj0'></sub></form><legend id='CfBj0'></legend><bdo id='CfBj0'><pre id='CfBj0'><center id='CfBj0'></center></pre></bdo></b><th id='CfBj0'></th></span></q></dt></tr></i><div id='CfBj0'><tfoot id='CfBj0'></tfoot><dl id='CfBj0'><fieldset id='CfBj0'></fieldset></dl></div>

                      • <bdo id='CfBj0'></bdo><ul id='CfBj0'></ul>

                    1. <tfoot id='CfBj0'></tfoot>