{"id":5478,"date":"2018-07-24T20:14:10","date_gmt":"2018-07-24T20:14:10","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/c-core-guidelines-the-noexcept-specifier-and-operator\/"},"modified":"2023-08-11T16:07:17","modified_gmt":"2023-08-11T16:07:17","slug":"c-core-guidelines-the-noexcept-specifier-and-operator","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/c-core-guidelines-the-noexcept-specifier-and-operator\/","title":{"rendered":"C++ Core Guidelines: The noexcept Specifier and Operator"},"content":{"rendered":"<p>If you skim the remaining rules to error handling, you often read the word&nbsp;<span style=\"font-family: 'courier new', courier;\">noexcept<\/span>. Before I write about the rules for error handling, I will write about the <span style=\"font-family: 'courier new', courier;\">noexcept<\/span> specifier and the <span style=\"font-family: 'courier new', courier;\">noexcept<\/span> operator in this post.&nbsp;<\/p>\n<p><!--more--><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5476\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/07\/teddy-562960_1280.jpg\" alt=\"teddy 562960 1280\" width=\"600\" height=\"486\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/07\/teddy-562960_1280.jpg 1280w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/07\/teddy-562960_1280-300x243.jpg 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/07\/teddy-562960_1280-1024x829.jpg 1024w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/07\/teddy-562960_1280-768x622.jpg 768w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<h2><span style=\"font-family: courier new, courier;\">noexcept<\/span><\/h2>\n<p><span style=\"font-family: courier new, courier;\">noexcept<\/span> exists in two forms since C++11: as a specifier and as an operator. The C++ core guidelines use the specifier.<\/p>\n<h3><span style=\"font-family: courier new, courier;\">noexcept<\/span> as specifier<\/h3>\n<p>By declaring a function, a method, or a lambda function as <span style=\"font-family: courier new, courier;\">noexcept<\/span>, you specify that these do not throw an exception, and if they throw, you do not care and let the program crash. For simplicity reasons, I will write about function but also mean methods and function templates. There are various ways to express your intention:<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">func1<\/span>() noexcept;        <span style=\"color: #0099ff; font-style: italic;\">\/\/ does not throw<\/span>\n<span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">func2<\/span>() noexcept(<span style=\"color: #336666;\">true<\/span>);  <span style=\"color: #0099ff; font-style: italic;\">\/\/ does not throw<\/span>\n<span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">func3<\/span>() <span style=\"color: #006699; font-weight: bold;\">throw<\/span>();         <span style=\"color: #0099ff; font-style: italic;\">\/\/ does not throw<\/span>\n\n<span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">func4<\/span>() noexcept(<span style=\"color: #336666;\">false<\/span>); <span style=\"color: #0099ff; font-style: italic;\">\/\/ may throw<\/span>\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>The <span style=\"font-family: courier new, courier;\">noexcept<\/span> specification is equivalent to the <span style=\"font-family: courier new, courier;\">noexcept(true)<\/span> specification.<span style=\"font-family: courier new, courier;\"> throw(<\/span>) is equivalent to <span style=\"font-family: courier new, courier;\">noexcept(tru<\/span>e) but was deprecated with C++11 and will be removed with C++20. In contrast, <span style=\"font-family: courier new, courier;\">noexcept(false)<\/span> means that the function may throw an exception. The <span style=\"font-family: courier new, courier;\">noexcept<\/span> specification is part of the function type but can not be used for function overloading.&nbsp;<\/p>\n<p>There are two good reasons for using <span style=\"font-family: courier new, courier;\">noexcept<\/span>: First, an exception specifier documents the function&#8217;s behavior. If a function is specified as <span style=\"font-family: courier new, courier;\">noexcept<\/span>, it can be safely used in a non-throwing function. Second, it is an optimization opportunity for the compiler. <span style=\"font-family: courier new, courier;\">noexcept<\/span> may not call <code style=\"background-color: #ffffff; color: #000000; font-size: 12.8px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;\"><\/code><span style=\"color: #000000; font-family: DejaVuSans, 'DejaVu Sans', arial, sans-serif; font-size: 12.8px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; background-color: #ffffff; float: none;\"><\/span><span class=\"t-lc\" style=\"color: #000000; font-size: 12.8px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; background-color: #ffffff; font-family: courier new, courier;\"><a href=\"https:\/\/en.cppreference.com\/w\/cpp\/error\/unexpected\" style=\"text-decoration: none; color: #0b0080; background: rgba(0, 0, 0, 0) none repeat scroll 0% 0%;\" title=\"cpp\/error\/unexpected\">std::unexpected<\/a><\/span><span style=\"color: #000000; font-family: DejaVuSans, 'DejaVu Sans', arial, sans-serif; font-size: 12.8px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; background-color: #ffffff; float: none;\"><\/span>and may not unwind the stack. The initialization of a container may cheaply move the elements into the container if the move constructor is declared as noexcept. If not declared as noexcept, the elements may be expensive copied into the container.<br \/>\n<span style=\"color: #000000; font-family: DejaVuSans, 'DejaVu Sans', arial, sans-serif; font-size: 12.8px; font-style: normal; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; background-color: #ffffff; float: none;\"><\/span><\/p>\n<p>Each function in C++ is either&nbsp;non-throwing&nbsp;or&nbsp;potentially throwing. Potentially throwing means:<\/p>\n<ol>\n<li>The function may use a function that may throw.<\/li>\n<li>The function is declared without a&nbsp;<span style=\"font-family: courier new, courier;\">noexcept<\/span> specification.<\/li>\n<li>The function uses a <span style=\"font-family: courier new, courier;\">dynamic_cast<\/span> to a reference type.<\/li>\n<\/ol>\n<p>There is an exception to rule 2, that functions are potentially throwing if they have no <span style=\"font-family: courier new, courier;\">noexcept<\/span> specification. These exceptions include the following six special member functions. They are implicitly non-throwing.<i style=\"color: #000000; font-family: DejaVuSans, 'DejaVu Sans', arial, sans-serif; font-size: 12.8px; font-weight: 400; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; background-color: #ffffff;\"> <\/i><\/p>\n<ul>\n<li>Default constructor and destructor<\/li>\n<li>Move and copy constructor<\/li>\n<li>Move and copy assignment operator<\/li>\n<\/ul>\n<p>This special six member such as the destructor, can only be non-throwing if all destructors of the attributes and the bases-classes are non-throwing. Of course, the corresponding statement will hold for the five other special member functions.<\/p>\n<p>What happens when you throw an exception in a function declared non-throwing? In this case,<span style=\"font-family: courier new, courier;\"><\/span> <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/error\/terminate\"><span style=\"font-family: courier new, courier;\">std::terminate<\/span><\/a> is called. <span style=\"font-family: courier new, courier;\">std::terminate<\/span> calls the currently installed <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/error\/terminate_handler\">std::terminate_handler<\/a> which calls <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/utility\/program\/abort\">std::abort<\/a>&nbsp;by default.The result is an abnormal program termination.<\/p>\n<p>For completeness, is want to present&nbsp;<span style=\"font-family: courier new, courier;\">noexcept<\/span> as operator.<\/p>\n<h3><span style=\"font-family: courier new, courier;\">noexcept<\/span> as operator<\/h3>\n<p>The <span style=\"font-family: courier new, courier;\"><code>noexcept<\/code><\/span> operator checks at compile-time if an expression does not throw an exception. The <span style=\"font-family: courier new, courier;\">noexcept<\/span> operator does not evaluate the expression. It can be used in a <span style=\"font-family: courier new, courier;\">noexcept<\/span> specifier of a function template to declare that the function may throw exceptions depending on the current type.<\/p>\n<p>To make my description clear, here is a simple example of a function template that copies its return value.<\/p>\n<p>&nbsp;<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ noexceptOperator.cpp<\/span>\n\n<span style=\"color: #009999;\">#include &lt;iostream&gt;<\/span>\n<span style=\"color: #009999;\">#include &lt;array&gt;<\/span>\n<span style=\"color: #009999;\">#include &lt;vector&gt;<\/span>\n\n<span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">NoexceptCopy<\/span>{\n<span style=\"color: #9999ff;\">public:<\/span>\n  std<span style=\"color: #555555;\">::<\/span>array<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span>, <span style=\"color: #ff6600;\">5<\/span><span style=\"color: #555555;\">&gt;<\/span> arr{<span style=\"color: #ff6600;\">1<\/span>, <span style=\"color: #ff6600;\">2<\/span>, <span style=\"color: #ff6600;\">3<\/span>, <span style=\"color: #ff6600;\">4<\/span>, <span style=\"color: #ff6600;\">5<\/span>};             <span style=\"color: #0099ff; font-style: italic;\">\/\/ (2)<\/span>\n};\n\n<span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">NonNoexceptCopy<\/span>{\n<span style=\"color: #9999ff;\">public:<\/span>\n  std<span style=\"color: #555555;\">::<\/span>vector<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;<\/span> v{<span style=\"color: #ff6600;\">1<\/span>, <span style=\"color: #ff6600;\">2<\/span>, <span style=\"color: #ff6600;\">3<\/span>, <span style=\"color: #ff6600;\">4<\/span> , <span style=\"color: #ff6600;\">5<\/span>};                <span style=\"color: #0099ff; font-style: italic;\">\/\/ (3)<\/span>\n};\n\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">typename<\/span> T<span style=\"color: #555555;\">&gt;<\/span> \nT copy(T <span style=\"color: #006699; font-weight: bold;\">const<\/span><span style=\"color: #555555;\">&amp;<\/span> src) noexcept(noexcept(T(src))){     <span style=\"color: #0099ff; font-style: italic;\">\/\/ (1)<\/span>\n  <span style=\"color: #006699; font-weight: bold;\">return<\/span> src; \n}\n\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> main(){\n    \n    NoexceptCopy noexceptCopy;\n    NonNoexceptCopy nonNoexceptCopy;\n    \n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>boolalpha <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\n    \n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"noexcept(copy(noexceptCopy)): \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span>            <span style=\"color: #0099ff; font-style: italic;\">\/\/ (4)<\/span>\n                  noexcept(copy(noexceptCopy)) <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\n                   \n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"noexcept(copy(nonNoexceptCopy)): \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span>         <span style=\"color: #0099ff; font-style: italic;\">\/\/ (5)<\/span>\n                  noexcept(copy(nonNoexceptCopy)) <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\n\n    std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>endl;\n\n}\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Of course, the most exciting line in this example is line (1). In particular,<span> the <\/span>expression <span style=\"font-family: courier new, courier;\">noexcept(noexcept(T(src)). <\/span>The inner noexcept ist the <span style=\"font-family: courier new, courier;\">noexcept<\/span> operator, and the outer is the <span style=\"font-family: courier new, courier;\">noexcept<\/span> specifier. The expression <span style=\"font-family: courier new, courier;\">noexcept(T(src))<\/span> checks if the copy constructor is non-throwing<span style=\"font-family: courier new, courier;\">.<\/span>This is the case for the class<span style=\"font-family: courier new, courier;\"> Noexcept <\/span>(2) but not for the class<span style=\"font-family: courier new, courier;\"> NonNoexcept (3) b<\/span>ecause of the copy constructor of<span style=\"font-family: courier new, courier;\">&nbsp;std::vector&nbsp;<\/span>that may throw<span style=\"font-family: courier new, courier;\">.<\/span> Consequently, expression (4) returns <span style=\"font-family: courier new, courier;\">true<\/span>, and expression (5) returns <span style=\"font-family: courier new, courier;\">false.<br \/>\n<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-5477\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/07\/noexceptOperator.png\" alt=\"noexceptOperator\" width=\"400\" height=\"168\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/07\/noexceptOperator.png 496w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2018\/07\/noexceptOperator-300x126.png 300w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/p>\n<p>Maybe you know about it. You can check at compile time with the help of the type traits library if a type T has a non-throwing copy constructor: <span style=\"font-family: courier new, courier;\">std::is_nothrow_copy_constructible::value<\/span>. Based on this predicate, you can use instead of the noexcept operator the predicate from the type traits library:<\/p>\n<p>&nbsp;<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">typename<\/span> T<span style=\"color: #555555;\">&gt;<\/span> \nT copy(T <span style=\"color: #006699; font-weight: bold;\">const<\/span><span style=\"color: #555555;\">&amp;<\/span> src) noexcept(std<span style=\"color: #555555;\">::<\/span>is_nothrow_copy_constructible<span style=\"color: #555555;\">&lt;<\/span>T<span style=\"color: #555555;\">&gt;::<\/span>value){\n  <span style=\"color: #006699; font-weight: bold;\">return<\/span> src; \n}\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>I don&#8217;t know which version of <span style=\"font-family: courier new, courier;\">copy<\/span> do you prefer. I prefer the type traits version because it is more expressive.<\/p>\n<p>The following rule&nbsp;is about the noexcept specifier.<\/p>\n<h2><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-noexcept\">E.12: Use <code class=\"highlighter-rouge no-highlight\">noexcept<\/code> when exiting a function because of a <code class=\"highlighter-rouge no-highlight\">throw<\/code> is impossible or unacceptable<\/a><\/h2>\n<p>The title of this rule may be a little bit confusing. It says that you should declare a function as <span style=\"font-family: courier new, courier;\">noexcept,<\/span> if<\/p>\n<ul>\n<li>it does not throw or<\/li>\n<li>you don&#8217;t care in case of an exception. You&nbsp;are willing to crash the program because you can not handle an exception such as <a href=\"https:\/\/en.cppreference.com\/w\/cpp\/memory\/new\/bad_alloc\"><span style=\"font-family: courier new, courier;\">std::bad_alloc<\/span><\/a> due to memory exhaustion.<\/li>\n<\/ul>\n<p>&nbsp;It&#8217;s not a good idea to throw an exception if you are the direct owner of an object.<\/p>\n<h2><a href=\"http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-never-throw\">E.13: Never throw while being the direct owner of an object<\/a><\/h2>\n<p>Here is an example to direct ownership from the guidelines:<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">leak<\/span>(<span style=\"color: #007788; font-weight: bold;\">int<\/span> x)   <span style=\"color: #0099ff; font-style: italic;\">\/\/ don't: may leak<\/span>\n{\n    <span style=\"color: #006699; font-weight: bold;\">auto<\/span> p <span style=\"color: #555555;\">=<\/span> <span style=\"color: #006699; font-weight: bold;\">new<\/span> <span style=\"color: #007788; font-weight: bold;\">int<\/span>{<span style=\"color: #ff6600;\">7<\/span>};\n    <span style=\"color: #006699; font-weight: bold;\">if<\/span> (x <span style=\"color: #555555;\">&lt;<\/span> <span style=\"color: #ff6600;\">0<\/span>) <span style=\"color: #006699; font-weight: bold;\">throw<\/span> Get_me_out_of_here{};  <span style=\"color: #0099ff; font-style: italic;\">\/\/ may leak *p<\/span>\n    <span style=\"color: #0099ff; font-style: italic;\">\/\/ ...<\/span>\n    <span style=\"color: #006699; font-weight: bold;\">delete<\/span> p;   <span style=\"color: #0099ff; font-style: italic;\">\/\/ we may never get here<\/span>\n}\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>If the throw is fired, the memory is lost, and you leak. The simple solution is to remove the ownership and make the C++ runtime to the direct owner of the object. Just create a local object or at least a guard as a local object. And you know the C++ runtime takes care of local objects. Here are three variations of this idea.<\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #007788; font-weight: bold;\">void<\/span> <span style=\"color: #cc00ff;\">leak<\/span>(<span style=\"color: #007788; font-weight: bold;\">int<\/span> x)   <span style=\"color: #0099ff; font-style: italic;\">\/\/ don't: may leak<\/span>\n{\n    <span style=\"color: #006699; font-weight: bold;\">auto<\/span> p1 <span style=\"color: #555555;\">=<\/span> <span style=\"color: #007788; font-weight: bold;\">int<\/span>{<span style=\"color: #ff6600;\">7<\/span>};\n    <span style=\"color: #006699; font-weight: bold;\">auto<\/span> p2 <span style=\"color: #555555;\">=<\/span> std<span style=\"color: #555555;\">::<\/span>make_unique<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;<\/span>(<span style=\"color: #ff6600;\">7<\/span>);\n    <span style=\"color: #006699; font-weight: bold;\">auto<\/span> p3 <span style=\"color: #555555;\">=<\/span> std<span style=\"color: #555555;\">::<\/span>vector<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;<\/span>(<span style=\"color: #ff6600;\">7<\/span>);\n    <span style=\"color: #006699; font-weight: bold;\">if<\/span> (x <span style=\"color: #555555;\">&lt;<\/span> <span style=\"color: #ff6600;\">0<\/span>) <span style=\"color: #006699; font-weight: bold;\">throw<\/span> Get_me_out_of_here{}; \n    <span style=\"color: #0099ff; font-style: italic;\">\/\/ ...<\/span>\n}\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p><span style=\"font-family: courier new, courier;\">p1<\/span> is locally created, but <span style=\"font-family: courier new, courier;\">p2<\/span> and <span style=\"font-family: courier new, courier;\">p3<\/span> are kinds of guards for the objects. The <span style=\"font-family: courier new, courier;\">std::vector <\/span>uses the heap to manage its data. Additionally, with all three variations, you eliminate the delete call.<span style=\"font-family: courier new, courier;\"> <\/span><\/p>\n<h2>What&#8217;s next?<\/h2>\n<p>Of course, my story, with exceptions and error handling, continues in the <a href=\"https:\/\/www.modernescpp.com\/&lt;p&gt;Today's post is about the right way to throw and catch exceptions. This means in particular when you should throw and how you should catch an exception.&lt;\/p&gt; &lt;hr id=&quot;system-readmore&quot; \/&gt; &lt;p&gt;&lt;img style=&quot;display: block; margin-left: auto; margin-right: auto;&quot; src=&quot;images\/blog\/ModernCpp\/CppCoreGuidelinesExceptionHandling\/disappointment-3151237_1280.jpg&quot; alt=&quot;disappointment 3151237 1280&quot; width=&quot;700&quot; height=&quot;466&quot; \/&gt;&lt;\/p&gt; &lt;p&gt;Here are the rules for today:&lt;\/p&gt; &lt;ul&gt; &lt;li&gt;&lt;a href=&quot;http:\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-exception-types&quot;&gt;E.14: Use purpose-designed user-defined types as exceptions (not built-in types)&lt;\/a&gt;&lt;\/li&gt; &lt;li&gt;&lt;a href=&quot;http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-exception-ref&quot;&gt;E.15: Catch exceptions from a hierarchy by reference&lt;\/a&gt;&lt;\/li&gt; &lt;li&gt;&lt;a href=&quot;http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-never-fail&quot;&gt;E.16: Destructors, deallocation, and &lt;code class=&quot;highlighter-rouge no-highlight&quot;&gt;swap&lt;\/code&gt; must never fail&lt;\/a&gt;&lt;\/li&gt; &lt;li&gt;&lt;a href=&quot;http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-not-always&quot;&gt;E.17: Don\u2019t try to catch every exception in every function&lt;\/a&gt;&lt;\/li&gt; &lt;li&gt;&lt;a href=&quot;http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-catch&quot;&gt;E.18: Minimize the use of explicit &lt;code class=&quot;highlighter-rouge no-highlight&quot;&gt;try&lt;\/code&gt;\/&lt;code class=&quot;highlighter-rouge no-highlight&quot;&gt;catch&lt;\/code&gt;&lt;\/a&gt;&lt;\/li&gt; &lt;\/ul&gt; &lt;p&gt;Let me directly jump into the first one.&lt;\/p&gt; &lt;h2&gt;&lt;a href=&quot;http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-exception-types&quot;&gt;E.14: Use purpose-designed user-defined types as exceptions (not built-in types)&lt;\/a&gt;&lt;\/h2&gt; &lt;p&gt;You should not use standard exceptions types or even built-in types as an exception. Here are the two don't from the guidelines:&lt;\/p&gt; &lt;h3&gt;A built-in type&lt;\/h3&gt; &lt;div style=&quot;background: #f0f3f3 none repeat scroll 0% 0%; overflow: auto; width: auto; border-width: 0.1em 0.1em 0.1em 0.8em;&quot;&gt; &lt;pre style=&quot;margin: 0px; line-height: 125%;&quot;&gt;&lt;span style=&quot;color: #007788; font-weight: bold;&quot;&gt;void&lt;\/span&gt; &lt;span style=&quot;color: #cc00ff;&quot;&gt;my_code&lt;\/span&gt;()     &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ Don't&lt;\/span&gt; {     &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ ...&lt;\/span&gt;     &lt;span style=&quot;color: #006699; font-weight: bold;&quot;&gt;throw&lt;\/span&gt; &lt;span style=&quot;color: #ff6600;&quot;&gt;7&lt;\/span&gt;;       &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ 7 means &quot;moon in the 4th quarter&quot;&lt;\/span&gt;     &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ ...&lt;\/span&gt; }  &lt;span style=&quot;color: #007788; font-weight: bold;&quot;&gt;void&lt;\/span&gt; &lt;span style=&quot;color: #cc00ff;&quot;&gt;your_code&lt;\/span&gt;()   &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ Don't&lt;\/span&gt; {     try {         &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ ...&lt;\/span&gt;         my_code();         &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ ...&lt;\/span&gt;     }     &lt;span style=&quot;color: #006699; font-weight: bold;&quot;&gt;catch&lt;\/span&gt;(&lt;span style=&quot;color: #007788; font-weight: bold;&quot;&gt;int&lt;\/span&gt; i) {  &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ i == 7 means &quot;input buffer too small&quot;&lt;\/span&gt;         &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ ...&lt;\/span&gt;     } } &lt;\/pre&gt; &lt;\/div&gt; &lt;p&gt;&amp;nbsp;&lt;\/p&gt; &lt;p&gt;In this case, the exception is just an &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;int&lt;\/span&gt; without any semantic. What &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;7 &lt;\/span&gt;mean stands in the comment, but should better be a self-describing type. The comment can be wrong. To be sure, you have to look up in the documentation to get an idea. You can not attach any meaningful information to an exception of kind &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;int&lt;\/span&gt;. If you have a &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;7&lt;\/span&gt;, I assume, you use at least the numbers 1 to 6 for your exception handling. &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;1&lt;\/span&gt; meaning an unspecific error and so on. This is way too sophisticated, error-prone, and quite hard to read and to maintain.&lt;\/p&gt; &lt;h3&gt;A standard exception&lt;\/h3&gt; &lt;div style=&quot;background: #f0f3f3 none repeat scroll 0% 0%; overflow: auto; width: auto; border-width: 0.1em 0.1em 0.1em 0.8em;&quot;&gt; &lt;pre style=&quot;margin: 0px; line-height: 125%;&quot;&gt;&lt;span style=&quot;color: #007788; font-weight: bold;&quot;&gt;void&lt;\/span&gt; &lt;span style=&quot;color: #cc00ff;&quot;&gt;my_code&lt;\/span&gt;()   &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ Don't&lt;\/span&gt; {     &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ ...&lt;\/span&gt;     &lt;span style=&quot;color: #006699; font-weight: bold;&quot;&gt;throw&lt;\/span&gt; runtime_error{&lt;span style=&quot;color: #cc3300;&quot;&gt;&quot;moon in the 4th quarter&quot;&lt;\/span&gt;};     &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ ...&lt;\/span&gt; }  &lt;span style=&quot;color: #007788; font-weight: bold;&quot;&gt;void&lt;\/span&gt; &lt;span style=&quot;color: #cc00ff;&quot;&gt;your_code&lt;\/span&gt;()   &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ Don't&lt;\/span&gt; {     try {         &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ ...&lt;\/span&gt;         my_code();         &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ ...&lt;\/span&gt;     }     &lt;span style=&quot;color: #006699; font-weight: bold;&quot;&gt;catch&lt;\/span&gt;(&lt;span style=&quot;color: #006699; font-weight: bold;&quot;&gt;const&lt;\/span&gt; runtime_error&lt;span style=&quot;color: #555555;&quot;&gt;&amp;amp;&lt;\/span&gt;) {   &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ runtime_error means &quot;input buffer too small&quot;&lt;\/span&gt;         &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ ...&lt;\/span&gt;     } } &lt;\/pre&gt; &lt;\/div&gt; &lt;p&gt;&amp;nbsp;&lt;\/p&gt; &lt;p&gt;Using a standard exception instead of a built-in type is better because you can attach additional information to an exception or build hierarchies of exceptions. This is better but not good.&amp;nbsp; Why? The exception is too generic. It's just a &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;runtime_error&lt;\/span&gt;. Image the function &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;my_code&lt;\/span&gt; is part of an input sub-system. If the caller of the function catches the exception by &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;std::runtime_error,&lt;\/span&gt; he has no idea if it was a generic error such as &quot;&lt;span style=&quot;font-family: courier new, courier;&quot;&gt;input buffer too small&lt;\/span&gt;&quot; or a sub-system specific error such as &quot;&lt;span style=&quot;font-family: courier new, courier;&quot;&gt;input device is not connected&lt;\/span&gt;&quot;.&lt;\/p&gt; &lt;p&gt;To overcome these issues derive your specific exception from &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;std::exception&lt;\/span&gt;. Here is a short example to give you the idea:&lt;\/p&gt; &lt;div style=&quot;background: #f0f3f3 none repeat scroll 0% 0%; overflow: auto; width: auto; border-width: 0.1em 0.1em 0.1em 0.8em;&quot;&gt; &lt;pre style=&quot;margin: 0px; line-height: 125%;&quot;&gt;&lt;span style=&quot;color: #006699; font-weight: bold;&quot;&gt;class&lt;\/span&gt; &lt;span style=&quot;color: #00aa88; font-weight: bold;&quot;&gt;InputSubSystemException&lt;\/span&gt;&lt;span style=&quot;color: #555555;&quot;&gt;:&lt;\/span&gt; &lt;span style=&quot;color: #006699; font-weight: bold;&quot;&gt;public&lt;\/span&gt; std&lt;span style=&quot;color: #555555;&quot;&gt;::&lt;\/span&gt;exception{     &lt;span style=&quot;color: #006699; font-weight: bold;&quot;&gt;const&lt;\/span&gt; &lt;span style=&quot;color: #007788; font-weight: bold;&quot;&gt;char&lt;\/span&gt;&lt;span style=&quot;color: #555555;&quot;&gt;*&lt;\/span&gt; what() &lt;span style=&quot;color: #006699; font-weight: bold;&quot;&gt;const&lt;\/span&gt; noexcept override {         &lt;span style=&quot;color: #006699; font-weight: bold;&quot;&gt;return&lt;\/span&gt; &lt;span style=&quot;color: #cc3300;&quot;&gt;&quot;Provide more details to the exception&quot;&lt;\/span&gt;;     } }; &lt;\/pre&gt; &lt;\/div&gt; &lt;p&gt;Now, the client of the input sub-system can specifically catch the exception via&lt;span style=&quot;font-family: courier new, courier;&quot;&gt; catch(const InputSubSystemException&amp;amp; ex)&lt;\/span&gt;. Additionally, you can refine the exception hierarchy by further deriving from the class &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;InputSubSystemException.&lt;\/span&gt;&lt;\/p&gt; &lt;h2&gt;&lt;a href=&quot;http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-exception-ref&quot;&gt;E.15: Catch exceptions from a hierarchy by reference&lt;\/a&gt;&lt;\/h2&gt; &lt;p&gt;If you catch an exception from a hierarchy by-value, you may become a victim of slicing.&lt;\/p&gt; &lt;p&gt;Imagine, you derive from &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;InputSubSystemException&lt;\/span&gt; (rule E.14) a new exception class &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;USBInputException&lt;\/span&gt; and catch the exception by-value of type &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;InputSubSystemException.&lt;\/span&gt;&lt;span style=&quot;font-family: courier new, courier;&quot;&gt; &lt;\/span&gt;&lt;span style=&quot;font-family: courier new, courier;&quot;&gt;&lt;span style=&quot;font-family: Helvetica, Arial, sans-serif;&quot;&gt;Now, an exception of type&lt;\/span&gt;&lt;\/span&gt;&lt;span style=&quot;font-family: courier new, courier;&quot;&gt;&lt;span style=&quot;font-family: Helvetica, Arial, sans-serif;&quot;&gt; &lt;\/span&gt;&lt;\/span&gt;&lt;span style=&quot;font-family: courier new, courier;&quot;&gt;USBInputException&lt;\/span&gt; is thrown.&lt;\/p&gt; &lt;div style=&quot;background: #f0f3f3 none repeat scroll 0% 0%; overflow: auto; width: auto; border-width: 0.1em 0.1em 0.1em 0.8em;&quot;&gt; &lt;pre style=&quot;margin: 0px; line-height: 125%;&quot;&gt;&lt;span style=&quot;color: #007788; font-weight: bold;&quot;&gt;void&lt;\/span&gt; &lt;span style=&quot;color: #cc00ff;&quot;&gt;subSystem&lt;\/span&gt;(){     &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ ...&lt;\/span&gt;     &lt;span style=&quot;color: #006699; font-weight: bold;&quot;&gt;throw&lt;\/span&gt; &lt;span style=&quot;color: #00aa88; font-weight: bold;&quot;&gt;USBInputException&lt;\/span&gt;&lt;span style=&quot;color: #555555;&quot;&gt;();&lt;\/span&gt;     &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ ...&lt;\/span&gt; }  &lt;span style=&quot;color: #007788; font-weight: bold;&quot;&gt;void&lt;\/span&gt; &lt;span style=&quot;color: #cc00ff;&quot;&gt;clientCode&lt;\/span&gt;(){     try{         subSystem();     }     &lt;span style=&quot;color: #006699; font-weight: bold;&quot;&gt;catch&lt;\/span&gt;(InputSubSystemException e) {   &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ slicing may happen&lt;\/span&gt;         &lt;span style=&quot;color: #0099ff; font-style: italic;&quot;&gt;\/\/ ...&lt;\/span&gt;     } } &lt;\/pre&gt; &lt;\/div&gt; &lt;p&gt;&amp;nbsp;&lt;\/p&gt; &lt;p&gt;By catching the &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;USBInputException&lt;\/span&gt; by-value to &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;InputSubSystemException, &lt;\/span&gt;slicing kicks in and &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;e&lt;\/span&gt; has the simpler type&amp;nbsp; &lt;span style=&quot;font-family: courier new, courier;&quot;&gt;InputSubSystemException. &lt;\/span&gt;Read the details of slicing in my previous post: &lt;a href=&quot;index.php\/c-core-guidelines-do-s-and-don-ts&quot;&gt;C++ Core Guidelines: Rules about Don'ts. &lt;\/a&gt;&lt;span style=&quot;font-family: Times New Roman, Times, serif;&quot;&gt;&lt;br \/&gt;&lt;\/span&gt;&lt;\/p&gt; &lt;p&gt;To say it explicitly:&lt;\/p&gt; &lt;ol&gt; &lt;li&gt;Catch your exception by const reference and only by reference if you want to modify the exception.&lt;\/li&gt; &lt;li&gt;If you rethrow an exception e in the exception handler, just use throw and not throw e. In the second case, e would be copied.&lt;span style=&quot;font-family: courier new, courier;&quot;&gt;&lt;span style=&quot;font-family: Times New Roman, Times, serif;&quot;&gt;&lt;br \/&gt; &lt;\/span&gt;&lt;\/span&gt;&lt;\/li&gt; &lt;\/ol&gt; &lt;h2&gt;&lt;a href=&quot;http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-never-fail&quot;&gt;E.16: Destructors, deallocation, and &lt;code class=&quot;highlighter-rouge no-highlight&quot;&gt;swap&lt;\/code&gt; must never fail&lt;\/a&gt;&lt;\/h2&gt; &lt;p&gt;This rule&amp;nbsp;is quite obvious. Destructors and deallocations should never throw because their no reliable way to handle an exception during the destruction of an object.&lt;\/p&gt; &lt;p&gt;&lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;swap &lt;\/span&gt;is often used as a basic building block for implementing copy and move semantic for a type. If an exception happens during &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;swap &lt;\/span&gt;you are, therefore, left with a non-initialised or not fully initialised object. Read more about the noexcept swap here: &lt;a href=&quot;index.php\/c-core-guidelines-comparison-swap-and-hash&quot;&gt;C++ Core Guidelines: Comparison, Swap, and Hash&lt;\/a&gt;.&lt;span style=&quot;font-family: Times New Roman, Times, serif;&quot;&gt;&lt;br \/&gt;&lt;\/span&gt;&lt;\/p&gt; &lt;p&gt;The next two rules to the adequate usage of try and except are quite similar.&lt;\/p&gt; &lt;h2&gt;&lt;a href=&quot;http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-not-always&quot;&gt;E.17: Don\u2019t try to catch every exception in every function&lt;\/a&gt; and&lt;a href=&quot;http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-catch&quot;&gt; E.18: Minimize the use of explicit &lt;code class=&quot;highlighter-rouge no-highlight&quot;&gt;try&lt;\/code&gt;\/&lt;code class=&quot;highlighter-rouge no-highlight&quot;&gt;catch&lt;\/code&gt;&lt;\/a&gt;&lt;\/h2&gt; &lt;p&gt;From the control flow perspective, &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;try\/catch&lt;\/span&gt; has a lot in common with the &lt;span style=&quot;font-family: Courier New, Courier, monospace;&quot;&gt;goto &lt;\/span&gt;statement. This means if an exception is thrown, the control flow directly jumps to the exception handler which is maybe in a totally different function of even sub-system. At the end you may get &lt;a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Spaghetti_code&quot;&gt;spaghetti code&lt;\/a&gt;; meaning code that has a difficult to predict and to maintain control flow.&lt;\/p&gt; &lt;p&gt;In the end, we are back to rule &lt;a href=&quot;http:\/\/isocpp.github.io\/CppCoreGuidelines\/CppCoreGuidelines#Re-design&quot;&gt;E.1: Develop an error-handling strategy early in a design. &lt;\/a&gt;&lt;\/p&gt; &lt;p&gt;Now, the question is: How should you structure your exception handling? I think you should ask yourself the question: Is it possible to handle the exception locally? If yes, do it. If no, let the exception propagate until you can sufficiently handle it. Often sub-system boundaries are the appropriate place to handle exceptions because you want to protect the client of the sub-system for arbitrary exceptions. At the boundary level, you have the interface consisting of the regularly and irregularly control flow. The regular communication is the functional aspect of the interface or what the system should do. The irregular communication stands for the non-functional aspects or how the system should perform. A big part of the non-functional aspects is the exception-handling and, therefore, the right place to handle the propagated exceptions.&lt;\/p&gt; &lt;h2&gt;What's next?&lt;\/h2&gt; &lt;p&gt;Six rules to error handling are still left in the C++ core guidelines. They are the topic for the next post before I go on with the rules to constants and immutability.&lt;\/p&gt; &lt;p&gt;&amp;nbsp;&lt;\/p&gt; &lt;p&gt;&amp;nbsp;&lt;\/p&gt; &lt;p&gt;&amp;nbsp;&lt;\/p&gt; &lt;p&gt;&lt;strong&gt;Thanks a lot to my &lt;a href=&quot;https:\/\/www.patreon.com\/rainer_grimm&quot;&gt;Patreon Supporters&lt;\/a&gt;&lt;\/strong&gt;&lt;strong&gt;: Eric Pederson, Paul Baxter,&amp;nbsp; Meeting C++, Matt Braun, Avi Lachmish, Roman Postanciuc, and Venkata Ramesh Gudpati.&lt;\/strong&gt;&lt;\/p&gt; &lt;p&gt;&amp;nbsp;&lt;\/p&gt; &lt;table style=&quot;width: 800px; height: 250px;&quot; border=&quot;0&quot; cellpadding=&quot;8&quot;&gt;&lt;caption&gt; &lt;h2&gt;Get your e-book at leanpub:&lt;\/h2&gt; &lt;\/caption&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt; &lt;h4&gt;&lt;strong&gt;The C++ Standard Library&lt;\/strong&gt;&lt;\/h4&gt; &lt;\/td&gt; &lt;td&gt;&amp;nbsp;&lt;\/td&gt; &lt;td&gt; &lt;h4&gt;&lt;strong&gt;Concurrency With Modern C++&lt;\/strong&gt;&lt;\/h4&gt; &lt;\/td&gt; &lt;td style=&quot;width: 5px;&quot;&gt;&amp;nbsp;&lt;\/td&gt; &lt;td&gt; &lt;h4&gt;&lt;strong&gt;Get Both as one Bundle&lt;\/strong&gt;&lt;\/h4&gt; &lt;\/td&gt; &lt;\/tr&gt; &lt;tr&gt; &lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https:\/\/leanpub.com\/cpplibrary&quot;&gt;&lt;img style=&quot;border: medium none #000000;&quot; src=&quot;images\/books\/cover.png&quot; alt=&quot;cover&quot; width=&quot;173&quot; height=&quot;220&quot; \/&gt;&lt;\/a&gt;&lt;\/td&gt; &lt;td style=&quot;text-align: center;&quot;&gt;&amp;nbsp;&lt;\/td&gt; &lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https:\/\/leanpub.com\/concurrencywithmodernc&quot;&gt;&lt;img src=&quot;images\/books\/ConcurrencyCoverFrame.png&quot; alt=&quot;ConcurrencyCoverFrame&quot; width=&quot;173&quot; height=&quot;223&quot; \/&gt;&lt;\/a&gt;&lt;\/td&gt; &lt;td style=&quot;width: 5px; text-align: center;&quot;&gt;&amp;nbsp;&lt;\/td&gt; &lt;td style=&quot;width: 5px; text-align: center;&quot;&gt;&lt;a href=&quot;https:\/\/leanpub.com\/b\/thecstandardlibraryandconcurrencywithmodernc&quot;&gt;&lt;img src=&quot;images\/books\/bundle.png&quot; alt=&quot;bundle&quot; width=&quot;300&quot; height=&quot;192&quot; \/&gt;&lt;\/a&gt;&lt;a href=&quot;https:\/\/leanpub.com\/cpplibrary&quot;&gt;&lt;\/a&gt;&lt;\/td&gt; &lt;\/tr&gt; &lt;tr&gt; &lt;td&gt;With &lt;strong&gt;C++11,&lt;\/strong&gt; &lt;strong&gt;C++14, and C++17&lt;\/strong&gt; we got a lot of new C++ libraries. In addition, the existing ones are greatly improved. The key idea of my book is to give you the necessary information to the current C++ libraries in about 200 pages.&lt;\/td&gt; &lt;td style=&quot;width: 15px;&quot;&gt;&amp;nbsp;&lt;\/td&gt; &lt;td&gt; &lt;p style=&quot;text-align: justify;&quot;&gt;&lt;strong&gt;C++11&lt;\/strong&gt; is the first C++ standard that deals with concurrency. The story goes on with &lt;strong&gt;C++17&lt;\/strong&gt; and will continue with &lt;strong&gt;C++20&lt;\/strong&gt;.&lt;\/p&gt; &lt;p style=&quot;text-align: justify;&quot;&gt;I'll give you a detailed insight in the current and the upcoming concurrency in C++. This insight includes the theory and a lot of practice with more the 100 source files.&lt;\/p&gt; &lt;\/td&gt; &lt;td style=&quot;width: 15px;&quot;&gt;&amp;nbsp;&lt;\/td&gt; &lt;td&gt; &lt;div class=&quot;about-bundle__blurb&quot; data-reactid=&quot;.bi7877yjsc.2.1.0.5.0.1.0&quot;&gt; &lt;p&gt;Get my books &quot;&lt;strong&gt;The C++ Standard Library&lt;\/strong&gt;&quot; (including C++17) and &quot;&lt;strong&gt;Concurrency with Modern C++&lt;\/strong&gt;&quot; in a bundle.&lt;\/p&gt; &lt;p&gt;In sum, you get more than 600 pages full of modern C++ and more than 100 source files presenting concurrency in practice.&lt;\/p&gt; &lt;\/div&gt; &amp;nbsp;&lt;\/td&gt; &lt;\/tr&gt; &lt;\/tbody&gt; &lt;\/table&gt;\">next post.<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you skim the remaining rules to error handling, you often read the word&nbsp;noexcept. Before I write about the rules for error handling, I will write about the noexcept specifier and the noexcept operator in this post.&nbsp;<\/p>\n","protected":false},"author":21,"featured_media":5476,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[372],"tags":[],"class_list":["post-5478","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-modern-c"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5478","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=5478"}],"version-history":[{"count":1,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5478\/revisions"}],"predecessor-version":[{"id":8050,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/5478\/revisions\/8050"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/5476"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=5478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=5478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=5478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}