Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / contract / doc / html / boost / contract / assertion_failure.html
1 <html>
2 <head>
3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Class assertion_failure</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&#160;1.&#160;Boost.Contract 1.0.0">
8 <link rel="up" href="../../reference.html#header.boost.contract.core.exception_hpp" title="Header &lt;boost/contract/core/exception.hpp&gt;">
9 <link rel="prev" href="constructor_precondition.html" title="Class template constructor_precondition">
10 <link rel="next" href="bad_virtual_result_cast.html" title="Class bad_virtual_result_cast">
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="constructor_precondition.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../reference.html#header.boost.contract.core.exception_hpp"><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="bad_virtual_result_cast.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
24 </div>
25 <div class="refentry">
26 <a name="boost.contract.assertion_failure"></a><div class="titlepage"></div>
27 <div class="refnamediv">
28 <h2><span class="refentrytitle">Class assertion_failure</span></h2>
29 <p>boost::contract::assertion_failure &#8212; Exception typically used to report a contract assertion failure. </p>
30 </div>
31 <h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
32 <div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../reference.html#header.boost.contract.core.exception_hpp" title="Header &lt;boost/contract/core/exception.hpp&gt;">boost/contract/core/exception.hpp</a>&gt;
33
34 </span>
35 <span class="keyword">class</span> <a class="link" href="assertion_failure.html" title="Class assertion_failure">assertion_failure</a> <span class="special">:</span>
36   <span class="keyword">public</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span>, <span class="keyword">public</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">contract</span><span class="special">::</span><span class="identifier">exception</span>
37 <span class="special">{</span>
38 <span class="keyword">public</span><span class="special">:</span>
39   <span class="comment">// <a class="link" href="assertion_failure.html#boost.contract.assertion_failureconstruct-copy-destruct">construct/copy/destruct</a></span>
40   <span class="keyword">explicit</span> <a class="link" href="assertion_failure.html#idm45394999500624-bb"><span class="identifier">assertion_failure</span></a><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> <span class="special">=</span> <span class="string">""</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> 
41                              <span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> <span class="special">=</span> <span class="string">""</span><span class="special">)</span><span class="special">;</span>
42   <span class="keyword">explicit</span> <a class="link" href="assertion_failure.html#idm45394999493584-bb"><span class="identifier">assertion_failure</span></a><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span><span class="special">)</span><span class="special">;</span>
43   <a class="link" href="assertion_failure.html#idm45394999491104-bb"><span class="special">~</span><span class="identifier">assertion_failure</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
44
45   <span class="comment">// <a class="link" href="assertion_failure.html#idm45394999515280-bb">public member functions</a></span>
46   <span class="keyword">virtual</span> <span class="keyword">char</span> <span class="keyword">const</span>  <span class="special">*</span> <a class="link" href="assertion_failure.html#idm45394999514720-bb"><span class="identifier">what</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
47   <span class="keyword">char</span> <span class="keyword">const</span>  <span class="special">*</span> <a class="link" href="assertion_failure.html#idm45394999509616-bb"><span class="identifier">file</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
48   <span class="keyword">unsigned</span> <span class="keyword">long</span> <a class="link" href="assertion_failure.html#idm45394999506688-bb"><span class="identifier">line</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
49   <span class="keyword">char</span> <span class="keyword">const</span>  <span class="special">*</span> <a class="link" href="assertion_failure.html#idm45394999503760-bb"><span class="identifier">code</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
50 <span class="special">}</span><span class="special">;</span></pre></div>
51 <div class="refsect1">
52 <a name="idm45707996246096"></a><h2>Description</h2>
53 <p>This exception is thrown by code expanded by <code class="computeroutput"><a class="link" href="../../BOOST_CONTRACT_ASSERT.html" title="Macro BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</a></code> (but it can also be thrown by user code programmed manually without that macro). This exception is typically used to report contract assertion failures because it contains detailed information about the file name, line number, and source code of the asserted condition (so it can be used by this library to provide detailed error messages when handling contract assertion failures).</p>
54 <p>However, any other exception can be used to report a contract assertion failure (including user-defined exceptions). This library will call the appropriate contract failure handler function ( <code class="computeroutput"><a class="link" href="precondition_failure.html" title="Function precondition_failure">boost::contract::precondition_failure</a></code>, etc.) when this or any other exception is thrown while checking contracts (by default, these failure handler functions print an error message to <code class="computeroutput">std::cerr</code> and terminate the program, but they can be customized to take any other action).</p>
55 <p><span class="bold"><strong>See Also:</strong></span></p>
56 <p> <a class="link" href="../../boost_contract/advanced.html#boost_contract.advanced.throw_on_failures__and__noexcept__" title="Throw on Failures (and noexcept)"> Throw on Failure</a>,  <a class="link" href="../../boost_contract/extras.html#boost_contract.extras.no_macros__and_no_variadic_macros_" title="No Macros (and No Variadic Macros)"> No Macros</a> </p>
57 <p>
58 </p>
59 <p>
60 </p>
61 <div class="refsect2">
62 <a name="idm45707996238000"></a><h3>
63 <a name="boost.contract.assertion_failureconstruct-copy-destruct"></a><code class="computeroutput">assertion_failure</code> 
64         public
65        construct/copy/destruct</h3>
66 <div class="orderedlist"><ol class="orderedlist" type="1">
67 <li class="listitem">
68 <pre class="literallayout"><span class="keyword">explicit</span> <a name="idm45394999500624-bb"></a><span class="identifier">assertion_failure</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> file <span class="special">=</span> <span class="string">""</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> line <span class="special">=</span> <span class="number">0</span><span class="special">,</span> 
69                            <span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> code <span class="special">=</span> <span class="string">""</span><span class="special">)</span><span class="special">;</span></pre>Construct this object with file name, line number, and source code text of an assertion condition (all optional). <p>This constructor can also be used to specify no information (default constructor), or to specify only file name and line number but not source code text (because of the parameter default values).</p>
70 <p>
71 </p>
72 <div class="variablelist"><table border="0" class="variablelist compact">
73 <colgroup>
74 <col align="left" valign="top">
75 <col>
76 </colgroup>
77 <tbody><tr>
78 <td><p><span class="term">Parameters:</span></p></td>
79 <td><div class="variablelist"><table border="0" class="variablelist compact">
80 <colgroup>
81 <col align="left" valign="top">
82 <col>
83 </colgroup>
84 <tbody>
85 <tr>
86 <td><p><span class="term"><code class="computeroutput">code</code></span></p></td>
87 <td><p>Text listing the source code of the assertion condition. </p></td>
88 </tr>
89 <tr>
90 <td><p><span class="term"><code class="computeroutput">file</code></span></p></td>
91 <td><p>Name of the file containing the assertion (usually set using <code class="computeroutput">__FILE__</code>). </p></td>
92 </tr>
93 <tr>
94 <td><p><span class="term"><code class="computeroutput">line</code></span></p></td>
95 <td><p>Number of the line containing the assertion (usually set using <code class="computeroutput">__LINE__</code>). </p></td>
96 </tr>
97 </tbody>
98 </table></div></td>
99 </tr></tbody>
100 </table></div>
101 </li>
102 <li class="listitem">
103 <pre class="literallayout"><span class="keyword">explicit</span> <a name="idm45394999493584-bb"></a><span class="identifier">assertion_failure</span><span class="special">(</span><span class="keyword">char</span> <span class="keyword">const</span> <span class="special">*</span> code<span class="special">)</span><span class="special">;</span></pre>Construct this object only with the source code text of the assertion condition. <p>
104 </p>
105 <div class="variablelist"><table border="0" class="variablelist compact">
106 <colgroup>
107 <col align="left" valign="top">
108 <col>
109 </colgroup>
110 <tbody><tr>
111 <td><p><span class="term">Parameters:</span></p></td>
112 <td><div class="variablelist"><table border="0" class="variablelist compact">
113 <colgroup>
114 <col align="left" valign="top">
115 <col>
116 </colgroup>
117 <tbody><tr>
118 <td><p><span class="term"><code class="computeroutput">code</code></span></p></td>
119 <td><p>Text listing the source code of the assertion condition. </p></td>
120 </tr></tbody>
121 </table></div></td>
122 </tr></tbody>
123 </table></div>
124 </li>
125 <li class="listitem">
126 <pre class="literallayout"><a name="idm45394999491104-bb"></a><span class="special">~</span><span class="identifier">assertion_failure</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>Destruct this object. <p><span class="bold"><strong>Throws:</strong></span> This is declared <code class="computeroutput">noexcept</code> (or <code class="computeroutput">throw()</code> before C++11). </p>
127 </li>
128 </ol></div>
129 </div>
130 <div class="refsect2">
131 <a name="idm45707996196832"></a><h3>
132 <a name="idm45394999515280-bb"></a><code class="computeroutput">assertion_failure</code> public member functions</h3>
133 <div class="orderedlist"><ol class="orderedlist" type="1">
134 <li class="listitem">
135 <pre class="literallayout"><span class="keyword">virtual</span> <span class="keyword">char</span> <span class="keyword">const</span>  <span class="special">*</span> <a name="idm45394999514720-bb"></a><span class="identifier">what</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>String describing the failed assertion. <p><span class="bold"><strong>Throws:</strong></span> This is declared <code class="computeroutput">noexcept</code> (or <code class="computeroutput">throw()</code> before C++11).</p>
136 <p>
137 </p>
138 <div class="variablelist"><table border="0" class="variablelist compact">
139 <colgroup>
140 <col align="left" valign="top">
141 <col>
142 </colgroup>
143 <tbody><tr>
144 <td><p><span class="term">Returns:</span></p></td>
145 <td><p>A string formatted similarly to the following: <code class="computeroutput">assertion "`code()`" failed: file "`file()`", line `line()`</code> (where `` indicate execution quotes). File, line, and code will be omitted from this string if they were not specified when constructing this object. </p></td>
146 </tr></tbody>
147 </table></div>
148 </li>
149 <li class="listitem">
150 <pre class="literallayout"><span class="keyword">char</span> <span class="keyword">const</span>  <span class="special">*</span> <a name="idm45394999509616-bb"></a><span class="identifier">file</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Name of the file containing the assertion. <p>
151 </p>
152 <div class="variablelist"><table border="0" class="variablelist compact">
153 <colgroup>
154 <col align="left" valign="top">
155 <col>
156 </colgroup>
157 <tbody><tr>
158 <td><p><span class="term">Returns:</span></p></td>
159 <td><p>File name as specified at construction (or <code class="computeroutput">""</code> if no file was specified). </p></td>
160 </tr></tbody>
161 </table></div>
162 </li>
163 <li class="listitem">
164 <pre class="literallayout"><span class="keyword">unsigned</span> <span class="keyword">long</span> <a name="idm45394999506688-bb"></a><span class="identifier">line</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Number of the line containing the assertion. <p>
165 </p>
166 <div class="variablelist"><table border="0" class="variablelist compact">
167 <colgroup>
168 <col align="left" valign="top">
169 <col>
170 </colgroup>
171 <tbody><tr>
172 <td><p><span class="term">Returns:</span></p></td>
173 <td><p>Line number as specified at construction (or <code class="computeroutput">0</code> if no line number was specified). </p></td>
174 </tr></tbody>
175 </table></div>
176 </li>
177 <li class="listitem">
178 <pre class="literallayout"><span class="keyword">char</span> <span class="keyword">const</span>  <span class="special">*</span> <a name="idm45394999503760-bb"></a><span class="identifier">code</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>Text listing the source code of the assertion condition. <p>
179 </p>
180 <div class="variablelist"><table border="0" class="variablelist compact">
181 <colgroup>
182 <col align="left" valign="top">
183 <col>
184 </colgroup>
185 <tbody><tr>
186 <td><p><span class="term">Returns:</span></p></td>
187 <td><p>Assertion condition source code as specified at construction (or <code class="computeroutput">""</code> if no source code text was specified). </p></td>
188 </tr></tbody>
189 </table></div>
190 </li>
191 </ol></div>
192 </div>
193 </div>
194 </div>
195 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
196 <td align="left"></td>
197 <td align="right"><div class="copyright-footer">Copyright &#169; 2008-2019 Lorenzo Caminiti<p>
198         Distributed under the Boost Software License, Version 1.0 (see accompanying
199         file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
200       </p>
201 </div></td>
202 </tr></table>
203 <hr>
204 <div class="spirit-nav">
205 <a accesskey="p" href="constructor_precondition.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../reference.html#header.boost.contract.core.exception_hpp"><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="bad_virtual_result_cast.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
206 </div>
207 </body>
208 </html>