<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

        c++ exception : throwing std::string(C++ 异常:抛出 std::string)
        <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is the past-the-end iterator in STL C++?(STL C++ 中的最后迭代器是什么?)
                  vector::at vs. vector::operator[](vector::at 与 vector::operator[])
                  C++ equivalent of StringBuffer/StringBuilder?(C++ 等效于 StringBuffer/StringBuilder?)
                  Adding types to the std namespace(将类型添加到 std 命名空间)
                  Is the C++ std::set thread-safe?(C++ std::set 线程安全吗?)
                  How to use std::find/std::find_if with a vector of custom class objects?(如何将 std::find/std::find_if 与自定义类对象的向量一起使用?)

                  <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>

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

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