]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/exception/doc/tutorial_enable_error_info.html
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / exception / doc / tutorial_enable_error_info.html
1 <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
2 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
3 <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
4 <head>
5 <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
6 <title>integrating boost exception in existing exception class hierarchies</title>
7 <link href='reno.css' type='text/css' rel='stylesheet'/>
8 </head>
9 <body>
10 <div class="body-0">
11 <div class="body-1">
12 <div class="body-2">
13 <div>
14 <div id="boost_logo">
15 <a href="http://www.boost.org"><img style="border:0" src="../../../boost.png" alt="Boost" width="277" height="86"/></a>
16 </div>
17 <h1>Boost Exception</h1>
18 </div>
19 <!-- Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. -->
20 <!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
21 <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
22 <div class="RenoIncludeDIV"><div class="RenoAutoDIV"><h2>Integrating Boost Exception in Existing Exception Class Hierarchies</h2>
23 </div>
24 <p>Some exception hierarchies can not be modified to make boost::<span class="RenoLink"><a href="exception.html">exception</a></span> a base type. In this case, the <span class="RenoLink"><a href="enable_error_info.html">enable_error_info</a></span> function template can be used to make exception objects derive from boost::<span class="RenoLink"><a href="exception.html">exception</a></span> anyway. Here is an example:</p>
25 <pre>#include &lt;<span class="RenoLink"><a href="boost_exception_all_hpp.html">boost/exception/all.hpp</a></span>&gt;
26 #include &lt;stdexcept&gt;
27
28 typedef boost::<span class="RenoLink"><a href="error_info.html">error_info</a></span>&lt;struct tag_std_range_min,size_t&gt; std_range_min;
29 typedef boost::<span class="RenoLink"><a href="error_info.html">error_info</a></span>&lt;struct tag_std_range_max,size_t&gt; std_range_max;
30 typedef boost::<span class="RenoLink"><a href="error_info.html">error_info</a></span>&lt;struct tag_std_range_index,size_t&gt; std_range_index;
31
32 template &lt;class T&gt;
33 class
34 my_container
35 {
36 public:
37
38 size_t size() const;
39
40 T const &amp;
41 operator[]( size_t i ) const
42 {
43 if( i &gt; size() )
44 throw boost::<span class="RenoLink"><a href="enable_error_info.html">enable_error_info</a></span>(std::range_error("Index out of range")) &lt;&lt;
45 std_range_min(0) &lt;&lt;
46 std_range_max(size()) &lt;&lt;
47 std_range_index(i);
48 //....
49 }
50 };
51 </pre>
52 <p>The call to <span class="RenoLink"><a href="enable_error_info.html">enable_error_info</a></span>&lt;T&gt; gets us an object of <i>unspecified type</i> which is guaranteed to derive from both boost::<span class="RenoLink"><a href="exception.html">exception</a></span> and T. This makes it possible to use <span class="RenoLink"><a href="exception_operator_shl.html">operator&lt;&lt;</a></span> to store additional information in the exception object. The exception can be intercepted as T &amp;, so existing exception handling will not break. It can also be intercepted as boost::<span class="RenoLink"><a href="exception.html">exception</a></span> &amp;, so that <span class="RenoLink"><a href="tutorial_transporting_data.html">more information can be added to the exception at a later time</a></span>.</p>
53 </div><div class="RenoAutoDIV"><div class="RenoHR"><hr/></div>
54 See also: <span class="RenoPageList"><a href="boost-exception.html">Boost Exception</a>&nbsp;| <a href="motivation.html">Motivation</a></span>
55 </div>
56 <!-- Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. -->
57 <!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
58 <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
59 <div id="footer">
60 <p>
61 <a class="logo" href="http://jigsaw.w3.org/css-validator/check/referer"><img class="logo_pic" src="valid-css.png" alt="Valid CSS" height="31" width="88"/></a>
62 <a class="logo" href="http://validator.w3.org/check?uri=referer"><img class="logo_pic" src="valid-xhtml.png" alt="Valid XHTML 1.0" height="31" width="88"/></a>
63 <small>Copyright (c) 2006-2009 by Emil Dotchevski and Reverge Studios, Inc.<br/>
64 Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License, Version 1.0</a>.</small>
65 </p>
66 </div>
67 </div>
68 </div>
69 </div>
70 </body>
71 </html>