• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>uncaught_exceptions</title>
5<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../index.html" title="Chapter 1. Boost.Core">
8<link rel="up" href="../index.html" title="Chapter 1. Boost.Core">
9<link rel="prev" href="typeinfo.html" title="typeinfo">
10<link rel="next" href="use_default.html" title="use_default">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="typeinfo.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="use_default.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h2 class="title" style="clear: both">
27<a name="core.uncaught_exceptions"></a><a class="link" href="uncaught_exceptions.html" title="uncaught_exceptions">uncaught_exceptions</a>
28</h2></div></div></div>
29<div class="toc"><dl class="toc"><dt><span class="section"><a href="uncaught_exceptions.html#core.uncaught_exceptions.header_boost_core_uncaught_excep">Header
30      &lt;boost/core/uncaught_exceptions.hpp&gt;</a></span></dt></dl></div>
31<div class="simplesect">
32<div class="titlepage"><div><div><h3 class="title">
33<a name="idm45312825783888"></a>Authors</h3></div></div></div>
34<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
35          Andrey Semashev
36        </li></ul></div>
37</div>
38<div class="section">
39<div class="titlepage"><div><div><h3 class="title">
40<a name="core.uncaught_exceptions.header_boost_core_uncaught_excep"></a><a class="link" href="uncaught_exceptions.html#core.uncaught_exceptions.header_boost_core_uncaught_excep" title="Header &lt;boost/core/uncaught_exceptions.hpp&gt;">Header
41      &lt;boost/core/uncaught_exceptions.hpp&gt;</a>
42</h3></div></div></div>
43<p>
44        The header <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">core</span><span class="special">/</span><span class="identifier">uncaught_exceptions</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span></code>
45        defines the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">uncaught_exceptions</span></code> function, which is
46        a more portable implementation of the same named function introduced in C++17.
47        The function returns the number of the currently pending exceptions. When
48        that function returns a value greater than 0, throwing an exception from
49        a destructor can terminate the program.
50      </p>
51<p>
52        Unfortunately, the function cannot be implemented on every pre-C++17 compiler,
53        although the most commonly used compilers are supported. When the compiler
54        does not provide the necessary functionality, <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">uncaught_exceptions</span></code>
55        returns a non-zero value if at least one exception is pending (i.e. not necessarily
56        the number of pending exceptions), and <code class="computeroutput"><span class="identifier">BOOST_CORE_UNCAUGHT_EXCEPTIONS_EMULATED</span></code>
57        macro is defined.
58      </p>
59<div class="section">
60<div class="titlepage"><div><div><h4 class="title">
61<a name="core.uncaught_exceptions.header_boost_core_uncaught_excep.example"></a><a class="link" href="uncaught_exceptions.html#core.uncaught_exceptions.header_boost_core_uncaught_excep.example" title="Example">Example</a>
62</h4></div></div></div>
63<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">my_class</span>
64<span class="special">{</span>
65<span class="keyword">private</span><span class="special">:</span>
66    <span class="keyword">const</span> <span class="keyword">unsigned</span> <span class="keyword">int</span> <span class="identifier">m_exception_count</span><span class="special">;</span>
67
68<span class="keyword">public</span><span class="special">:</span>
69    <span class="identifier">my_class</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">m_exception_count</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">uncaught_exceptions</span><span class="special">())</span>
70    <span class="special">{</span>
71    <span class="special">}</span>
72
73    <span class="special">~</span><span class="identifier">my_class</span><span class="special">()</span> <span class="keyword">noexcept</span><span class="special">(</span><span class="keyword">false</span><span class="special">)</span>
74    <span class="special">{</span>
75        <span class="keyword">if</span> <span class="special">(</span><span class="identifier">m_exception_count</span> <span class="special">==</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">core</span><span class="special">::</span><span class="identifier">uncaught_exceptions</span><span class="special">())</span>
76            <span class="identifier">do_something_potentially_throwing</span><span class="special">();</span>
77    <span class="special">}</span>
78<span class="special">};</span>
79</pre>
80</div>
81</div>
82</div>
83<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
84<td align="left"></td>
85<td align="right"><div class="copyright-footer">Copyright © 2014 Peter Dimov<br>Copyright © 2014 Glen Fernandes<br>Copyright © 2014 Andrey Semashev<p>
86        Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
87        Software License, Version 1.0</a>.
88      </p>
89</div></td>
90</tr></table>
91<hr>
92<div class="spirit-nav">
93<a accesskey="p" href="typeinfo.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="use_default.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
94</div>
95</body>
96</html>
97