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

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

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

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

        如何拋出 C++ 異常

        How to throw a C++ exception(如何拋出 C++ 異常)
      3. <legend id='NOkgc'><style id='NOkgc'><dir id='NOkgc'><q id='NOkgc'></q></dir></style></legend>

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

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

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

                  <tbody id='NOkgc'></tbody>

                • 本文介紹了如何拋出 C++ 異常的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我對異常處理的理解很差(即,如何為自己的目的自定義 throw、try、catch 語句).

                  I have a very poor understanding of exception handling(i.e., how to customize throw, try, catch statements for my own purposes).

                  例如我定義了一個函數如下:int compare(int a, int b){...}

                  For example, I have defined a function as follows: int compare(int a, int b){...}

                  我希望函數在 a 或 b 為負數時拋出一個帶有一些消息的異常.

                  I'd like the function to throw an exception with some message when either a or b is negative.

                  我應該如何在函數定義中解決這個問題?

                  How should I approach this in the definition of the function?

                  推薦答案

                  簡單:

                  #include <stdexcept>
                  
                  int compare( int a, int b ) {
                      if ( a < 0 || b < 0 ) {
                          throw std::invalid_argument( "received negative value" );
                      }
                  }
                  

                  標準庫附帶了一個很好的內置異常對象你可以扔.請記住,您應該始終按值拋出并按引用捕獲:

                  The Standard Library comes with a nice collection of built-in exception objects you can throw. Keep in mind that you should always throw by value and catch by reference:

                  try {
                      compare( -1, 3 );
                  }
                  catch( const std::invalid_argument& e ) {
                      // do stuff with exception... 
                  }
                  

                  您可以在每次嘗試后使用多個 catch() 語句,因此您可以根據需要分別處理不同的異常類型.

                  You can have multiple catch() statements after each try, so you can handle different exception types separately if you want.

                  你也可以重新拋出異常:

                  You can also re-throw exceptions:

                  catch( const std::invalid_argument& e ) {
                      // do something
                  
                      // let someone higher up the call stack handle it if they want
                      throw;
                  }
                  

                  并捕獲不分類型的異常:

                  And to catch exceptions regardless of type:

                  catch( ... ) { };
                  

                  這篇關于如何拋出 C++ 異常的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 之間的區別)
                  • <i id='iSAnY'><tr id='iSAnY'><dt id='iSAnY'><q id='iSAnY'><span id='iSAnY'><b id='iSAnY'><form id='iSAnY'><ins id='iSAnY'></ins><ul id='iSAnY'></ul><sub id='iSAnY'></sub></form><legend id='iSAnY'></legend><bdo id='iSAnY'><pre id='iSAnY'><center id='iSAnY'></center></pre></bdo></b><th id='iSAnY'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='iSAnY'><tfoot id='iSAnY'></tfoot><dl id='iSAnY'><fieldset id='iSAnY'></fieldset></dl></div>
                      <bdo id='iSAnY'></bdo><ul id='iSAnY'></ul>
                      1. <small id='iSAnY'></small><noframes id='iSAnY'>

                        1. <tfoot id='iSAnY'></tfoot>
                          <legend id='iSAnY'><style id='iSAnY'><dir id='iSAnY'><q id='iSAnY'></q></dir></style></legend>
                              <tbody id='iSAnY'></tbody>

                            主站蜘蛛池模板: 欧美成人极品 | 亚洲成人免费网站 | 182tv午夜 | 波多野结衣一区二区三区在线观看 | 日韩在线观看一区 | 亚洲黄色三级 | 男人影院在线观看 | 国产在线视频91 | 欧美精品在线观看视频 | 欧美超碰在线 | 91精品一区 | 国产无精乱码一区二区三区 | 九九视频在线免费观看 | 国产亚洲一区二区三区 | 欧美在线中文字幕 | 精品国产999久久久免费 | 天天操免费视频 | 国产一区二区欧美 | 在线免费黄色网址 | 99久久精品国产毛片 | 亚洲图片一区二区 | 亚洲精品1区 | 日韩视频在线观看免费 | 青青久操 | 国产精品一区二区av | 黄网站免费在线观看 | 日本亚洲天堂 | 草少妇 | 国产精品1区2区 | 夜夜夜夜操 | 久草资源在线观看 | 国产精品国产精品国产专区不片 | 欧美成人毛片 | 一区二区三区中文字幕 | 久久男人天堂 | 天天看毛片 | 久久88| 欧美顶级黄色大片免费 | 亚洲欧美综合 | 成人在线国产 | 亚洲一级二级 |