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

    1. <tfoot id='4iyDZ'></tfoot>

      1. <small id='4iyDZ'></small><noframes id='4iyDZ'>

          <bdo id='4iyDZ'></bdo><ul id='4iyDZ'></ul>

        C++ 异常:抛出 std::string

        时间:2024-05-12
        <i id='BufOO'><tr id='BufOO'><dt id='BufOO'><q id='BufOO'><span id='BufOO'><b id='BufOO'><form id='BufOO'><ins id='BufOO'></ins><ul id='BufOO'></ul><sub id='BufOO'></sub></form><legend id='BufOO'></legend><bdo id='BufOO'><pre id='BufOO'><center id='BufOO'></center></pre></bdo></b><th id='BufOO'></th></span></q></dt></tr></i><div id='BufOO'><tfoot id='BufOO'></tfoot><dl id='BufOO'><fieldset id='BufOO'></fieldset></dl></div>
            <tbody id='BufOO'></tbody>
          <legend id='BufOO'><style id='BufOO'><dir id='BufOO'><q id='BufOO'></q></dir></style></legend>
              <bdo id='BufOO'></bdo><ul id='BufOO'></ul>
              <tfoot id='BufOO'></tfoot>

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

                1. 本文介绍了C++ 异常:抛出 std::string的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我的 C++ 方法遇到一些奇怪的事情并且无法恢复时,我想抛出一个异常.抛出一个 std::string 指针可以吗?

                  I would like to throw an exception when my C++ methods encounter something weird and can't recover. Is it OK to throw a std::string pointer?

                  这是我期待做的事情:

                  void Foo::Bar() {
                      if(!QueryPerformanceTimer(&m_baz)) {
                          throw new std::string("it's the end of the world!");
                      }
                  }
                  
                  void Foo::Caller() {
                      try {
                          this->Bar(); // should throw
                      }
                      catch(std::string *caught) { // not quite sure the syntax is OK here...
                          std::cout << "Got " << caught << std::endl;
                      }
                  }
                  

                  推荐答案

                  是的.std::exception 是C++ 标准库.您可能希望避免使用字符串作为异常类,因为它们本身在使用过程中会抛出异常.如果发生这种情况,那么你会在哪里?

                  Yes. std::exception is the base exception class in the C++ standard library. You may want to avoid using strings as exception classes because they themselves can throw an exception during use. If that happens, then where will you be?

                  boost 有一个优秀的文档,关于异常和错误处理的良好风格.值得一读.

                  boost has an excellent document on good style for exceptions and error handling. It's worth a read.

                  这篇关于C++ 异常:抛出 std::string的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将映射值复制到 STL 中的向量 下一篇:如何初始化“const std::vector&lt;T&gt;"像一个c数组

                  相关文章

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

                  1. <small id='1duc7'></small><noframes id='1duc7'>

                      • <bdo id='1duc7'></bdo><ul id='1duc7'></ul>