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

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

          <bdo id='dADhw'></bdo><ul id='dADhw'></ul>
      1. <legend id='dADhw'><style id='dADhw'><dir id='dADhw'><q id='dADhw'></q></dir></style></legend>

        C++、__try 和 try/catch/finally

        C++, __try and try/catch/finally(C++、__try 和 try/catch/finally)

      2. <tfoot id='0ggwF'></tfoot>
      3. <legend id='0ggwF'><style id='0ggwF'><dir id='0ggwF'><q id='0ggwF'></q></dir></style></legend>

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

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

                1. 本文介紹了C++、__try 和 try/catch/finally的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有點想知道 C++ try/catch/finally 塊.我見過這些帶有兩個下劃線的命令,比如 __try.但是 MVSC 2010 項目也沒有下劃線運行.那么什么時候需要這些下劃線?

                  I'm wondering a bit about C++ try/catch/finally blocks. I've seen these commands with two underscores like __try. But MVSC 2010 projects also run without the underscores. So when do you need these underscores?

                  推薦答案

                  在 Windows 上,在操作系統級別支持異常.稱為結構化異常處理 (SEH),它們大致相當于 Unix 信號.為 Windows 生成代碼的編譯器通常利用這一點,它們使用 SEH 基礎結構來實現 C++ 異常.

                  On Windows, exceptions are supported at the operating system level. Called Structured Exception Handling (SEH), they are the rough equivalent to Unix signals. Compilers that generate code for Windows typically take advantage of this, they use the SEH infrastructure to implement C++ exceptions.

                  為了與 C++ 標準保持一致,throwcatch 關鍵字只拋出和捕獲 C++ 異常.MSVC編譯器對應的SEH異常代碼是0xe06d7363.最后 3 個字節是msc"的 ASCII 碼.

                  In keeping with the C++ standard, the throw and catch keywords only ever throw and catch C++ exceptions. The corresponding SEH exception code for the MSVC compiler is 0xe06d7363. The last 3 bytes are the ASCII code for "msc".

                  將它與操作系統支持統一也意味著 C++ 析構函數將在堆棧展開期間為 SEH 異常調用.執行展開的代碼在 Windows 內部,并以與任何 SEH 完全相同的方式處理由 throw 引發的 SEH.但是,Microsoft 編譯器進行了優化,嘗試避免生成確保在所有情況下都調用析構函數所需的代碼.如果它可以證明在控制對象生命周期的范圍塊中沒有 throw 語句,那么它會跳過注冊代碼.這與異步 SEH 異常不兼容,如果您打算捕獲 SEH 異常,則應使用/EHa 編譯選項來抑制此優化.

                  Unifying it with the operating system support also means that C++ destructors will be called during stack unwinding for an SEH exception. The code that does the unwinding is inside Windows and treats the SEH raised by a throw the exact same way as any SEH. However, the Microsoft compiler has an optimization that tries to avoid generating the code required that ensures that destructors are called in all cases. If it can prove that there's no throw statement inside the scope block that controls the object's lifetime then it skips the registration code. This is not compatible with asynchronous SEH exceptions, you should use the /EHa compile option to suppress this optimization if you intend to catch SEH exceptions.

                  有很多 SEH 異常類型.操作系統可以生成的在ntstatus.h SDK頭文件中列出.此外,您可能會與使用 SEH 實現自己的異常處理的代碼互操作,他們將使用自己的異常代碼.與 .NET 一樣,托管異常使用 0xe0434f4d(com")異常代碼.

                  There are a lot of SEH exception types. The ones that can be generated by the operating system are listed in the ntstatus.h SDK header file. In addition, you might interop with code that uses SEH to implement their own exception handling, they will use their own exception code. Like .NET, managed exceptions use the 0xe0434f4d ("com") exception code.

                  要在 C++ 程序中捕獲 SEH 異常,您必須使用非標準的 __try 關鍵字.__except 關鍵字類似于 C++ catch 關鍵字.它具有更多功能,您可以指定一個異常過濾器表達式來確定是否應捕獲活動異常.一切皆有可能,但您通常只查看傳遞的異常信息,看看您是否有興趣處理它.__finally 關鍵字允許您編寫在處理異常后運行的代碼.在 C++ 中沒有等價物,但在其他語言中并不少見.

                  To catch SEH exceptions in a C++ program, you must use the non-standard __try keyword. The __except keyword is analogous to the C++ catch keyword. It has more capabilities, you specify an exception filter expression that determines whether or not an active exception should be caught. Anything is possible, but you typically only look at the passed exception information to see if you're interested in handling it. The __finally keyword lets you write code that runs after the exception is handled. No equivalent for that in C++ but not uncommon in other languages.

                  正如評論中指出的那樣,所有這些都沒有很好的記錄.證據就在布丁里.這是您可以使用的示例程序.它演示了 SEH 異常如何仍然允許調用 C++ 析構函數,前提是您使用/EHa 進行編譯以及如何在 SEH 之上實現 C++ 異常.需要 MSVC 編譯器,使用 Ctrl+F5 運行以避免調試器有用:

                  All of this is fairly poorly documented as pointed out in the comments. The proof is in the pudding. Here's an example program that you can play with. It demonstrates how SEH exceptions still allows for C++ destructors to be called, provided you compile with /EHa and how C++ exceptions are implemented on top of SEH. MSVC compiler required, run with Ctrl+F5 to avoid the debugger being helpful:

                  #include "stdafx.h"
                  #include <windows.h>
                  #include <iostream>
                  
                  // NOTE: the value of the C/C++, Code Generation, Enable C++ Exceptions setting in important
                  // Try it both with /EHsc (the default) and /EHa to see the difference
                  
                  class Example {  
                  public:
                      ~Example() { std::cout << "destructed" << std::endl; }
                  };
                  
                  int filterException(int code, PEXCEPTION_POINTERS ex) {
                      std::cout << "Filtering " << std::hex << code << std::endl;
                      return EXCEPTION_EXECUTE_HANDLER;
                  }
                  
                  void testProcessorFault() {
                      Example e;
                      int* p = 0;
                      *p = 42;
                  }
                  
                  void testCppException() {
                      Example e;
                      throw 42;
                  }
                  
                  int main()
                  {
                      __try {
                          testProcessorFault();
                      }
                      __except(filterException(GetExceptionCode(), GetExceptionInformation())) {
                          std::cout << "caught" << std::endl;
                      }
                      __try {
                          testCppException();
                      }
                      __except(filterException(GetExceptionCode(), GetExceptionInformation())) {
                          std::cout << "caught" << std::endl;
                      }
                      return 0;
                  }
                  

                  輸出:

                  Filtering c0000005
                  destructed
                  caught
                  Filtering e06d7363
                  destructed
                  caught
                  

                  這篇關于C++、__try 和 try/catch/finally的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 之間的區別)
                2. <tfoot id='AjOpM'></tfoot>
                        <legend id='AjOpM'><style id='AjOpM'><dir id='AjOpM'><q id='AjOpM'></q></dir></style></legend>

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

                          <tbody id='AjOpM'></tbody>

                          <bdo id='AjOpM'></bdo><ul id='AjOpM'></ul>

                          <i id='AjOpM'><tr id='AjOpM'><dt id='AjOpM'><q id='AjOpM'><span id='AjOpM'><b id='AjOpM'><form id='AjOpM'><ins id='AjOpM'></ins><ul id='AjOpM'></ul><sub id='AjOpM'></sub></form><legend id='AjOpM'></legend><bdo id='AjOpM'><pre id='AjOpM'><center id='AjOpM'></center></pre></bdo></b><th id='AjOpM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='AjOpM'><tfoot id='AjOpM'></tfoot><dl id='AjOpM'><fieldset id='AjOpM'></fieldset></dl></div>
                            主站蜘蛛池模板: 亚洲免费视频一区二区 | 国产三级大片 | 久视频在线观看 | 久久久久久久久久久久久九 | 特级黄一级播放 | 午夜精品一区二区三区在线视频 | 免费国产黄网站在线观看视频 | 午夜一区二区三区视频 | 亚洲综合免费 | 五月婷六月丁香 | 黄色日批视频 | 欧洲妇女成人淫片aaa视频 | 欧美一二三区 | 看羞羞视频免费 | 第四色狠狠| 国产综合在线视频 | 国产精品久久久久久久久 | 中文字幕精品一区二区三区精品 | 国产欧美日韩精品一区二区三区 | 99精品在线| www.日韩| 欧美区在线观看 | 中文字幕在线播放第一页 | 久一精品 | 日韩在线看片 | 日韩一区中文字幕 | 亚洲国产精品va在线看黑人 | 国产免费观看视频 | 国产精品综合色区在线观看 | av激情影院| 91精品国产自产精品男人的天堂 | 香蕉视频黄色 | 欧美激情一区二区三级高清视频 | 免费精品 | 国产亚洲一区二区三区在线 | 国产亚洲日本精品 | av日日操 | 欧美精品一区在线 | 国产精品入口久久 | 性色av香蕉一区二区 | 亚洲成人www |