久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

      1. <legend id='MUEW7'><style id='MUEW7'><dir id='MUEW7'><q id='MUEW7'></q></dir></style></legend>
      2. <tfoot id='MUEW7'></tfoot>

        為什么 C++ 不使用 std::nested_exception 來允許從析構

        Why doesn#39;t C++ use std::nested_exception to allow throwing from destructor?(為什么 C++ 不使用 std::nested_exception 來允許從析構函數拋出?)
          <tbody id='0gr55'></tbody>

          <small id='0gr55'></small><noframes id='0gr55'>

          • <bdo id='0gr55'></bdo><ul id='0gr55'></ul>
            <tfoot id='0gr55'></tfoot>

              <legend id='0gr55'><style id='0gr55'><dir id='0gr55'><q id='0gr55'></q></dir></style></legend>

              <i id='0gr55'><tr id='0gr55'><dt id='0gr55'><q id='0gr55'><span id='0gr55'><b id='0gr55'><form id='0gr55'><ins id='0gr55'></ins><ul id='0gr55'></ul><sub id='0gr55'></sub></form><legend id='0gr55'></legend><bdo id='0gr55'><pre id='0gr55'><center id='0gr55'></center></pre></bdo></b><th id='0gr55'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0gr55'><tfoot id='0gr55'></tfoot><dl id='0gr55'><fieldset id='0gr55'></fieldset></dl></div>
                1. 本文介紹了為什么 C++ 不使用 std::nested_exception 來允許從析構函數拋出?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  從析構函數拋出異常的主要問題是,在調用析構函數的那一刻,另一個異常可能是飛行中"(std::uncaught_exception() == true),所以它是在這種情況下該怎么做并不明顯.用新的覆蓋"舊的例外將是處理這種情況的可能方法之一.但決定在這種情況下必須調用 std::terminate(或另一個 std::terminate_handler).

                  The main problem with throwing exceptions from destructor is that in the moment when destructor is called another exception may be "in flight" (std::uncaught_exception() == true) and so it is not obvious what to do in that case. "Overwriting" the old exception with the new one would be the one of the possible ways to handle this situation. But it was decided that std::terminate (or another std::terminate_handler) must be called in such cases.

                  C++11 通過 std::nested_exception 類引入了嵌套異常功能.此功能可用于解決上述問題.舊的(未捕獲的)異常可以嵌套到新的異常中(反之亦然?),然后可以拋出嵌套的異常.但是這個想法沒有被使用.std::terminate 在 C++11 和 C++14 中仍然會在這種情況下被調用.

                  C++11 introduced nested exceptions feature via std::nested_exception class. This feature could be used to solve the problem described above. The old (uncaught) exception could be just nested into the new exception (or vice versa?) and then that nested exception could be thrown. But this idea was not used. std::terminate is still called in such situation in C++11 and C++14.

                  所以問題.是否考慮了嵌套異常的想法?它有什么問題嗎?C++17不會改變這種情況嗎?

                  So the questions. Was the idea with nested exceptions considered? Are there any problems with it? Isn't the situation going to be changed in the C++17?

                  推薦答案

                  當您的析構函數作為堆棧展開過程的一部分執行時(當您的對象不是作為堆棧展開的一部分創建時),您引用的問題就會發生1,并且您的析構函數需要發出異常.

                  The problem you cite happens when your destructor is being executed as part of the stack unwinding process (when your object was not created as part of stack unwinding)1, and your destructor needs to emit an exception.

                  那么它是如何工作的呢?你有兩個例外.異常 X 是導致堆棧展開的異常.異常 Y 是析構函數想要拋出的異常.nested_exception 只能容納一個.

                  So how does that work? You have two exceptions in play. Exception X is the one that's causing the stack to unwind. Exception Y is the one that the destructor wants to throw. nested_exception can only hold one of them.

                  所以也許你有異常 Y contain 一個 nested_exception(或者可能只是一個 exception_ptr).那么...你如何在 catch 站點處理這個問題?

                  So maybe you have exception Y contain a nested_exception (or maybe just an exception_ptr). So... how do you deal with that at the catch site?

                  如果你捕捉到Y,并且它恰好有一些嵌入的X,你怎么得到它?記住:exception_ptr類型擦除;除了傳遞它之外,你唯一能做的就是重新扔掉它.所以人們應該這樣做嗎:

                  If you catch Y, and it happens to have some embedded X, how do you get it? Remember: exception_ptr is type-erased; aside from passing it around, the only thing you can do with it is rethrow it. So should people be doing this:

                  catch(Y &e)
                  {
                    if(e.has_nested())
                    {
                      try
                      {
                        e.rethrow_nested();
                      }
                      catch(X &e2)
                      {
                      }
                    }
                  }
                  

                  我沒有看到很多人這樣做.尤其是因為可能存在大量的 X-es.

                  I don't see a lot of people doing that. Especially since there would be an exceedingly large number of possible X-es.

                  1:請不要使用 std::uncaught_exception() == true 來檢測這種情況.這是非常有缺陷的.

                  1: Please do not use std::uncaught_exception() == true to detect this case. It is extremely flawed.

                  這篇關于為什么 C++ 不使用 std::nested_exception 來允許從析構函數拋出?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  In what ways do C++ exceptions slow down code when there are no exceptions thown?(當沒有異常時,C++ 異常會以何種方式減慢代碼速度?)
                  Why catch an exception as reference-to-const?(為什么要捕獲異常作為對 const 的引用?)
                  When and how should I use exception handling?(我應該何時以及如何使用異常處理?)
                  Scope of exception object in C++(C++中異常對象的范圍)
                  Catching exceptions from a constructor#39;s initializer list(從構造函數的初始化列表中捕獲異常)
                  Difference between C++03 throw() specifier C++11 noexcept(C++03 throw() 說明符 C++11 noexcept 之間的區別)

                    <tbody id='tvtA2'></tbody>
                    <bdo id='tvtA2'></bdo><ul id='tvtA2'></ul>
                  • <i id='tvtA2'><tr id='tvtA2'><dt id='tvtA2'><q id='tvtA2'><span id='tvtA2'><b id='tvtA2'><form id='tvtA2'><ins id='tvtA2'></ins><ul id='tvtA2'></ul><sub id='tvtA2'></sub></form><legend id='tvtA2'></legend><bdo id='tvtA2'><pre id='tvtA2'><center id='tvtA2'></center></pre></bdo></b><th id='tvtA2'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='tvtA2'><tfoot id='tvtA2'></tfoot><dl id='tvtA2'><fieldset id='tvtA2'></fieldset></dl></div>
                    <legend id='tvtA2'><style id='tvtA2'><dir id='tvtA2'><q id='tvtA2'></q></dir></style></legend>
                      1. <small id='tvtA2'></small><noframes id='tvtA2'>

                        <tfoot id='tvtA2'></tfoot>

                          • 主站蜘蛛池模板: 久久精品在线播放 | 黄色国产精品 | 人人草人人爽 | 黄色精品视频 | 免费视频久久久 | 天天看天天射 | 蜜桃av一区 | av高清在线| 九九热在线精品视频 | 国产精品一区二区免费 | 日韩影音 | 小sao货撅起屁股扒开c微博 | 91久久国产综合久久91精品网站 | 99在线免费观看 | 欧美色婷婷 | 最新91视频| 91成人精品一区在线播放 | 日韩av在线不卡 | 国产精品久久久久久久久 | 免费网站观看www在线观看 | 欧美色图一区二区三区 | 免费看成人片 | 黄色一级视频网站 | 欧美一级在线视频 | 免费看一级黄色片 | aaa成人| 亚洲精品视频在线观看免费 | 国产视频一区在线观看 | 91福利视频导航 | 欧美大片18| 精品一区在线 | 一级做a爱片性色毛片 | 91亚洲精品在线 | 不卡av网站 | 欧美精品日韩少妇 | www.中文字幕 | 波多野结衣之双调教hd | 日韩精品一区二区在线 | 色综合久久天天综合网 | 在线视频一区二区三区 | 在线黄网 |