<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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                  Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)

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