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

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

      1. 从构造函数的初始化列表中捕获异常

        时间:2023-08-03

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

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

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

                  本文介绍了从构造函数的初始化列表中捕获异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  这是一个奇怪的问题.我有一个 A 类.它有一个 B 类项目,我想在 A 的构造函数中使用初始化列表对其进行初始化,如下所示:

                  Here's a curious one. I have a class A. It has an item of class B, which I want to initialize in the constructor of A using an initializer list, like so:

                  class A {
                      public:
                      A(const B& b): mB(b) { };
                  
                      private:
                      B mB;
                  };
                  

                  有没有办法在仍然使用初始化列表方法的同时捕获可能由 mB 的复制构造函数抛出的异常?或者我是否必须在构造函数的大括号内初始化 mB 才能进行 try/catch?

                  Is there a way to catch exceptions that might be thrown by mB's copy-constructor while still using the initializer list method? Or would I have to initialize mB within the constructor's braces in order to have a try/catch?

                  推荐答案

                  阅读http://weseetips.wordpress.com/tag/exception-from-constructor-initializer-list/)

                  经过更多挖掘,这些被称为功能尝试块".

                  After more digging, these are called "Function try blocks".

                  我承认在我去看之前我也不知道这一点.你每天都会学到一些东西!我不知道这是否是对我这些天很少使用 C++、我缺乏 C++ 知识,或者语言中经常出现的拜占庭特性的控诉.嗯 - 我仍然喜欢它:)

                  I confess I didn't know this either until I went looking. You learn something every day! I don't know if this is an indictment of how little I get to use C++ these days, my lack of C++ knowledge, or the often Byzantine features that litter the language. Ah well - I still like it :)

                  为了确保人们不必跳转到另一个站点,构造函数的 try 块的语法结果是:

                  To ensure people don't have to jump to another site, the syntax of a function try block for constructors turns out to be:

                  C::C()
                  try : init1(), ..., initn()
                  {
                    // Constructor
                  }
                  catch(...)
                  {
                    // Handle exception
                  }
                  

                  这篇关于从构造函数的初始化列表中捕获异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:C++03 throw() 说明符 C++11 noexcept 之间的区别 下一篇:C++中异常对象的范围

                  相关文章

                  最新文章

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

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

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