久久久久久久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 來允許從析構(gòu)

        Why doesn#39;t C++ use std::nested_exception to allow throwing from destructor?(為什么 C++ 不使用 std::nested_exception 來允許從析構(gòu)函數(shù)拋出?)
          <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 來允許從析構(gòu)函數(shù)拋出?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  從析構(gòu)函數(shù)拋出異常的主要問題是,在調(diào)用析構(gòu)函數(shù)的那一刻,另一個異常可能是飛行中"(std::uncaught_exception() == true),所以它是在這種情況下該怎么做并不明顯.用新的覆蓋"舊的例外將是處理這種情況的可能方法之一.但決定在這種情況下必須調(diào)用 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 中仍然會在這種情況下被調(diào)用.

                  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?

                  推薦答案

                  當(dāng)您的析構(gòu)函數(shù)作為堆棧展開過程的一部分執(zhí)行時(當(dāng)您的對象不是作為堆棧展開的一部分創(chuàng)建時),您引用的問題就會發(fā)生1,并且您的析構(gòu)函數(shù)需要發(fā)出異常.

                  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 是導(dǎo)致堆棧展開的異常.異常 Y 是析構(gòu)函數(shù)想要拋出的異常.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類型擦除;除了傳遞它之外,你唯一能做的就是重新扔掉它.所以人們應(yīng)該這樣做嗎:

                  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.

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

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

                  相關(guān)文檔推薦

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

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

                          • 主站蜘蛛池模板: 色综合天天天天做夜夜夜夜做 | 亚洲精品一区国产精品 | 欧美精品一区三区 | 精品久久久999 | 亚洲视频免费在线看 | 日韩成人影院 | 91精品国产一区二区三区香蕉 | 成人免费视频网站在线看 | 亚洲精品第一 | 国产亚洲精品美女久久久久久久久久 | 久久精品国产一区二区三区 | 久久国产亚洲 | 久久这里只有精品首页 | 99久视频 | 亚洲国产欧美日韩 | 成人性视频免费网站 | 国产精品精品久久久久久 | 99精品观看 | 碰碰视频 | a级毛片毛片免费观看久潮喷 | 国产精品成人一区二区三区夜夜夜 | 日韩中文字幕在线观看 | 国产一级电影在线 | 亚洲一区二区三区四区av | 国产免费一区 | 日韩精品一区二区三区在线播放 | zzzwww在线看片免费 | 精品国产第一区二区三区 | 欧美日韩福利 | 欧美日韩久久久久 | 成人久久久 | 国产亚洲精品久久久优势 | 99久久精品国产一区二区三区 | 精品一区二区三区四区视频 | 丝袜美腿一区二区三区动态图 | 9久久婷婷国产综合精品性色 | 天堂在线中文字幕 | 欧美日日日日bbbbb视频 | 中文一区二区 | www.99热| 久久久久国产精品www |