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

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

    1. <legend id='oCcCi'><style id='oCcCi'><dir id='oCcCi'><q id='oCcCi'></q></dir></style></legend>
      <tfoot id='oCcCi'></tfoot>
      • <bdo id='oCcCi'></bdo><ul id='oCcCi'></ul>

      应该捕获 boost::asio::io_service::run() 抛出的异常吗

      时间:2023-08-03

        <legend id='efrao'><style id='efrao'><dir id='efrao'><q id='efrao'></q></dir></style></legend>

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

          • <tfoot id='efrao'></tfoot>
          • <small id='efrao'></small><noframes id='efrao'>

              1. 本文介绍了应该捕获 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_thrown_from_handlers

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

                上一篇:谁删除了在“新建"期间分配的内存?构造函数 下一篇:C++03 throw() 说明符 C++11 noexcept 之间的区别

                相关文章

                最新文章

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

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

              3. <tfoot id='DQzQp'></tfoot>
                  <bdo id='DQzQp'></bdo><ul id='DQzQp'></ul>

                  1. <legend id='DQzQp'><style id='DQzQp'><dir id='DQzQp'><q id='DQzQp'></q></dir></style></legend>