<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          C++核心準(zhǔn)則E.12: 當(dāng)不可能或不愿意通過拋出異常退出函數(shù)時使用noe...

          133d609149512913c0cea0308c1f7014.webp

          E.12: Use?noexcept?when exiting a function because of a?throw?is impossible or unacceptable

          E.12: 當(dāng)不可能或不愿意通過拋出異常退出函數(shù)時使用noexcept


          Reason(原因)

          To make error handling systematic, robust, and efficient.

          為了讓錯誤處理更系統(tǒng)化,健壯和高效。


          Example(示例)

          double compute(double d) noexcept
          {
          return log(sqrt(d <= 0 ? 1 : d));
          }

          Here, we know that?compute?will not throw because it is composed out of operations that don't throw. By declaring?compute?to be?noexcept, we give the compiler and human readers information that can make it easier for them to understand and manipulate?compute.

          因為這段代碼有不會拋出異常的操作構(gòu)成,所以我們知道compute函數(shù)不會拋出異常。通過將compute函數(shù)定義為noexcept,我向編譯器和代碼的讀者傳遞了可以讓它們更容易理解和維護代碼的信息。


          Note(注意)

          Many standard-library functions are?noexcept?including all the standard-library functions "inherited" from the C Standard Library.

          很多標(biāo)準(zhǔn)庫函數(shù)被定義為noexcept,包含所有從C標(biāo)準(zhǔn)庫繼承的標(biāo)準(zhǔn)庫函數(shù)。


          Example(示例)

          vector munge(const vector& v) noexcept
          {
          vector v2(v.size());
          // ... do something ...
          }

          The?noexcept?here states that I am not willing or able to handle the situation where I cannot construct the local?vector. That is, I consider memory exhaustion a serious design error (on par with hardware failures) so that I'm willing to crash the program if it happens.

          這里的noexcept說明我不愿意或者不能處理局部的vecrot構(gòu)建失敗的情況。也就是說,我認(rèn)為內(nèi)存耗盡是嚴(yán)重的設(shè)計錯誤(和硬件錯誤同樣看待),如果這種情況發(fā)生,我甘愿終止程序。


          Note(注意)

          Do not use traditional?exception-specifications.

          不要使用傳統(tǒng)的例外定義方式。


          See also(參見)

          discussion.

          課題討論。


          原文鏈接https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#e12-use-noexcept-when-exiting-a-function-because-of-a-throw-is-impossible-or-unacceptable

          新書介紹

          以下是本人3月份出版的新書,拜托多多關(guān)注!


          313c1e24e561e3517773d4248da5e8c3.webp

          本書利用Python 的標(biāo)準(zhǔn)GUI 工具包tkinter,通過可執(zhí)行的示例對23 個設(shè)計模式逐個進行說明。這樣一方面可以使讀者了解真實的軟件開發(fā)工作中每個設(shè)計模式的運用場景和想要解決的問題;另一方面通過對這些問題的解決過程進行說明,讓讀者明白在編寫代碼時如何判斷使用設(shè)計模式的利弊,并合理運用設(shè)計模式。

          對設(shè)計模式感興趣而且希望隨學(xué)隨用的讀者通過本書可以快速跨越從理解到運用的門檻;希望學(xué)習(xí)Python GUI 編程的讀者可以將本書中的示例作為設(shè)計和開發(fā)的參考;使用Python 語言進行圖像分析、數(shù)據(jù)處理工作的讀者可以直接以本書中的示例為基礎(chǔ),迅速構(gòu)建自己的系統(tǒng)架構(gòu)。




          覺得本文有幫助?請分享給更多人。

          關(guān)注微信公眾號【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!

          面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>



          瀏覽 15
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  国产三级在线免费观看 | 国产微拍精品一区 | 国产精品五月天 | 美女啪啪国产 | 亚洲有码在线播放 |