Documentation update

[SVN r52092]
This commit is contained in:
Emil Dotchevski
2009-03-31 22:20:46 +00:00
parent 6e909aaf58
commit d2c197d4e6
12 changed files with 6556 additions and 5682 deletions

View File

@ -25,10 +25,13 @@
<p>The ability to add data to exception objects after they have been passed to throw is important, because often some of the information needed to handle an exception is unavailable in the context where the failure is detected. </p> <p>The ability to add data to exception objects after they have been passed to throw is important, because often some of the information needed to handle an exception is unavailable in the context where the failure is detected. </p>
<p>Boost Exception also supports <span class="RenoLink"><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2179.html">N2179</a></span>-style <span class="RenoLink"><a href="tutorial_exception_ptr.html">copying</a></span> of exception objects, implemented non-intrusively and automatically by the boost::<span class="RenoLink"><a href="throw_exception.html">throw_exception</a></span> function.</p> <p>Boost Exception also supports <span class="RenoLink"><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2179.html">N2179</a></span>-style <span class="RenoLink"><a href="tutorial_exception_ptr.html">copying</a></span> of exception objects, implemented non-intrusively and automatically by the boost::<span class="RenoLink"><a href="throw_exception.html">throw_exception</a></span> function.</p>
<h2>Contents</h2> <h2>Contents</h2>
<div><ol><li>Tutorial<div><ol><li><span class="RenoLink"><a href="tutorial_transporting_data.html">Transporting of Arbitrary Data to the Catch Site</a></span></li> <div><ol><li><span class="RenoLink"><a href="motivation.html">Motivation</a></span></li>
<li>Tutorial<div><ol><li><span class="RenoLink"><a href="tutorial_transporting_data.html">Transporting of Arbitrary Data to the Catch Site</a></span></li>
<li><span class="RenoLink"><a href="tutorial_diagnostic_information.html">Diagnostic Information</a></span></li> <li><span class="RenoLink"><a href="tutorial_diagnostic_information.html">Diagnostic Information</a></span></li>
<li><span class="RenoLink"><a href="tutorial_enable_error_info.html">Integrating Boost Exception in Existing Exception Class Hierarchies</a></span></li> <li><span class="RenoLink"><a href="tutorial_enable_error_info.html">Integrating Boost Exception in Existing Exception Class Hierarchies</a></span></li>
<li><span class="RenoLink"><a href="tutorial_exception_ptr.html">Transporting of Exceptions Between Threads</a></span></li> <li><span class="RenoLink"><a href="tutorial_exception_ptr.html">Transporting of Exceptions Between Threads</a></span></li>
<li><span class="RenoLink"><a href="exception_types_as_simple_semantic_tags.html">Exception Types As Simple Semantic Tags</a></span></li>
<li><span class="RenoLink"><a href="using_virtual_inheritance_in_exception_types.html">Using Virtual Inheritance in Exception Types</a></span></li>
</ol></div> </ol></div>
</li> </li>
<li>Documentation<div><ol><li>Class <span class="RenoLink"><a href="exception.html">exception</a></span></li> <li>Documentation<div><ol><li>Class <span class="RenoLink"><a href="exception.html">exception</a></span></li>

View File

@ -61,6 +61,7 @@ typedef boost::<span class="RenoLink"><a href="error_info.html">error_info</a></
</a><a href="exception_operator_shl.html">exception/operator&lt;&lt;<br/> </a><a href="exception_operator_shl.html">exception/operator&lt;&lt;<br/>
</a><a href="get_error_info.html">get_error_info<br/> </a><a href="get_error_info.html">get_error_info<br/>
</a><a href="tutorial_enable_error_info.html">Integrating Boost Exception in Existing Exception Class Hierarchies<br/> </a><a href="tutorial_enable_error_info.html">Integrating Boost Exception in Existing Exception Class Hierarchies<br/>
</a><a href="motivation.html">Motivation<br/>
</a><a href="tuple_operator_shl.html">tuple/operator&lt;&lt;<br/> </a><a href="tuple_operator_shl.html">tuple/operator&lt;&lt;<br/>
</a></div> </a></div>
</div> </div>

View File

@ -47,6 +47,7 @@ boost
</a><a href="current_exception.html">current_exception<br/> </a><a href="current_exception.html">current_exception<br/>
</a><a href="tutorial_diagnostic_information.html">Diagnostic Information<br/> </a><a href="tutorial_diagnostic_information.html">Diagnostic Information<br/>
</a><a href="diagnostic_information.html">diagnostic_information<br/> </a><a href="diagnostic_information.html">diagnostic_information<br/>
</a><a href="exception_types_as_simple_semantic_tags.html">Exception Types As Simple Semantic Tags<br/>
</a><a href="enable_current_exception.html">enable_current_exception<br/> </a><a href="enable_current_exception.html">enable_current_exception<br/>
</a><a href="enable_error_info.html">enable_error_info<br/> </a><a href="enable_error_info.html">enable_error_info<br/>
</a><a href="error_info.html">error_info<br/> </a><a href="error_info.html">error_info<br/>
@ -55,9 +56,11 @@ boost
</a><a href="exception_destructor.html">exception::~exception<br/> </a><a href="exception_destructor.html">exception::~exception<br/>
</a><a href="get_error_info.html">get_error_info<br/> </a><a href="get_error_info.html">get_error_info<br/>
</a><a href="tutorial_enable_error_info.html">Integrating Boost Exception in Existing Exception Class Hierarchies<br/> </a><a href="tutorial_enable_error_info.html">Integrating Boost Exception in Existing Exception Class Hierarchies<br/>
</a><a href="motivation.html">Motivation<br/>
</a><a href="tutorial_transporting_data.html">Transporting of Arbitrary Data to the Catch Site<br/> </a><a href="tutorial_transporting_data.html">Transporting of Arbitrary Data to the Catch Site<br/>
</a><a href="tutorial_exception_ptr.html">Transporting of Exceptions Between Threads<br/> </a><a href="tutorial_exception_ptr.html">Transporting of Exceptions Between Threads<br/>
</a><a href="tuple_operator_shl.html">tuple/operator&lt;&lt;<br/> </a><a href="tuple_operator_shl.html">tuple/operator&lt;&lt;<br/>
</a><a href="using_virtual_inheritance_in_exception_types.html">Using Virtual Inheritance in Exception Types<br/>
</a><a href="unknown_exception.html">unknown_exception<br/> </a><a href="unknown_exception.html">unknown_exception<br/>
</a></div> </a></div>
<!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. --> <!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. -->

View File

@ -47,6 +47,7 @@ boost
</a><a href="exception_constructors.html">exception::exception<br/> </a><a href="exception_constructors.html">exception::exception<br/>
</a><a href="get_error_info.html">get_error_info<br/> </a><a href="get_error_info.html">get_error_info<br/>
</a><a href="tutorial_enable_error_info.html">Integrating Boost Exception in Existing Exception Class Hierarchies<br/> </a><a href="tutorial_enable_error_info.html">Integrating Boost Exception in Existing Exception Class Hierarchies<br/>
</a><a href="motivation.html">Motivation<br/>
</a></div> </a></div>
</div> </div>
<!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. --> <!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. -->

View File

@ -0,0 +1,56 @@
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>exception types as simple semantic tags</title>
<link href='reno.css' type='text/css' rel='stylesheet'/>
</head>
<body>
<div class="body-0">
<div class="body-1">
<div class="body-2">
<div>
<div id="boost_logo">
<a href="http://www.boost.org"><img style="border:0" src="http://www.boost.org/boost.png" alt="Boost" width="277" height="86"/></a>
</div>
<h1>Boost Exception</h1>
</div>
<!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. -->
<!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<div class="RenoIncludeDIV"><div class="RenoAutoDIV"><h3>Exception Types As Simple Semantic Tags</h3>
</div>
<p>Deriving from boost::<span class="RenoLink"><a href="exception.html">exception</a></span> effectively decouples the semantics of a failure from the information that is relevant to each individual instance of reporting a failure with a given semantic.</p>
<p>In other words: with boost::<span class="RenoLink"><a href="exception.html">exception</a></span>, what data a given exception object transports depends primarily on the context in which failures are reported (not on its type). Since exception types need no members, it becomes very natural to throw exceptions that derive from more than one type to indicate multiple appropriate semantics:</p>
<pre>struct exception_base: virtual std::exception, virtual boost::<span class="RenoLink"><a href="exception.html">exception</a></span> { };
struct io_error: virtual exception_base { };
struct file_error: virtual io_error { };
struct read_error: virtual io_error { };
struct file_read_error: virtual file_error, virtual read_error { };</pre>
<p>Using this approach, exception types become a simple tagging system for categorizing errors and selecting failures in exception handlers.</p>
</div><div class="RenoAutoDIV"><div class="RenoHR"><hr/></div>
<h3>See Also:</h3>
<div class="RenoPageList"><a href="boost-exception.html">Boost Exception<br/>
</a><a href="motivation.html">Motivation<br/>
</a><a href="using_virtual_inheritance_in_exception_types.html">Using Virtual Inheritance in Exception Types<br/>
</a></div>
</div>
<!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. -->
<!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<div id="footer">
<p>&nbsp;</p>
<hr/>
<p>
<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>
<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>
<small>Copyright (c) 2006-2008 by Emil Dotchevski and Reverge Studios, Inc.<br/>
Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License, Version 1.0</a>.</small>
</p>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@ -49,6 +49,7 @@ boost
</a><a href="configuration_macros.html">Configuration Macros<br/> </a><a href="configuration_macros.html">Configuration Macros<br/>
</a><a href="error_info.html">error_info<br/> </a><a href="error_info.html">error_info<br/>
</a><a href="exception.html">exception<br/> </a><a href="exception.html">exception<br/>
</a><a href="motivation.html">Motivation<br/>
</a></div> </a></div>
</div> </div>
<!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. --> <!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. -->

145
doc/motivation.html Normal file
View File

@ -0,0 +1,145 @@
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Motivation</title>
<link href='reno.css' type='text/css' rel='stylesheet'/>
</head>
<body>
<div class="body-0">
<div class="body-1">
<div class="body-2">
<div>
<div id="boost_logo">
<a href="http://www.boost.org"><img style="border:0" src="http://www.boost.org/boost.png" alt="Boost" width="277" height="86"/></a>
</div>
<h1>Boost Exception</h1>
</div>
<!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. -->
<!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<div class="RenoIncludeDIV"><div class="RenoAutoDIV"><h3>Motivation</h3>
</div>
<p>Traditionally, when using exceptions to report failures, the throw site:</p>
<div><ul><li>creates an exception object of the appropriate type, and</li>
<li>stuffs it with data relevant to the detected error.</li>
</ul></div>
<p>A higher context in the program contains a catch statement which:</p>
<div><ul><li>selects failures based on exception types, and</li>
<li>inspects exception objects for data required to deal with the problem.</li>
</ul></div>
<p>The main issue with this "traditional" approach is that often, the data available at the point of the throw is insufficient for the catch site to handle the failure.</p>
<p>Here is an example of a catch statement:</p>
<pre>catch( file_read_error &amp; e )
{
std::cerr &lt;&lt; e.file_name();
}</pre>
<p>And here is a possible matching throw:</p>
<pre>void
read_file( FILE * f )
{
....
size_t nr=fread(buf,1,count,f);
if( ferror(f) )
throw file_read_error(???);
....
}</pre>
<p>Clearly, the problem is that the handler requires a file name but the read_file function does not have a file name to put in the exception object; all it has is a FILE pointer!</p>
<p>In an attempt to deal with this problem, we could modify read_file to accept a file name:</p>
<pre>void
read_file( FILE * f, char const * name )
{
....
size_t nr=fread(buf,1,count,f);
if( ferror(f) )
throw file_read_error(name);
....
}</pre>
<p>This is not a real solution: it simply shifts the burden of supplying a file name to the immediate caller of the read_file function.</p>
<blockquote><p><i>In general, the data required to handle a given library-emitted exception depends on the program that links to it. Many contexts between the throw and the catch may have relevant information which must be transported to the exception handler.</i></p></blockquote>
<h3>Exception wrapping</h3>
<p>The idea of exception wrapping is to catch an exception from a lower level function (such as the read_file function above), and throw a new exception object that contains the original exception (and also carries a file name.) This method seems to be particularly popular with C++ programmers with Java background.</p>
<p>Exception wrapping leads to the following problems:</p>
<div><ol><li>To wrap an exception object it must be copied, which may result in slicing.</li>
<li>Wrapping is practically impossible to use in generic contexts.</li>
</ol></div>
<p>The second point is actually special case of violating the exception neutrality principle. Most contexts in a program can not handle exceptions; such contexts should not interfere with the process of exception handling.</p>
<h3>The boost::exception solution</h3>
<div><ul><li>Simply derive your exception types from boos::<span class="RenoLink"><a href="exception.html">exception</a></span>.</li>
<li>Confidently limit the throw site to provide only data that is available naturally.</li>
<li>Use exception-neutral contexts between the throw and the catch to augment exceptions with more relevant data as they bubble up.</li>
</ul></div>
<p>For example, in the throw statement below we only add the errno code, since this is the only failure-relevant information available in this context:</p>
<pre>struct exception_base: virtual std::exception, virtual boost::<span class="RenoLink"><a href="exception.html">exception</a></span> { };
struct file_read_error: virtual exception_base { };
typedef boost::<span class="RenoLink"><a href="error_info.html">error_info</a></span>&lt;struct tag_errno_code,int&gt; errno_code;
void
read_file( FILE * f )
{
....
size_t nr=fread(buf,1,count,f);
if( ferror(f) )
throw file_read_error() <span class="RenoLink"><a href="exception_operator_shl.html">&lt;&lt;</a></span> errno_code(errno);
....
}</pre>
<p>In a higher exception-neutral context, we add the file name to <i>any</i> exception that derives from boost::<span class="RenoLink"><a href="exception.html">exception</a></span>:</p>
<pre>typedef boost::<span class="RenoLink"><a href="error_info.html">error_info</a></span>&lt;struct tag_file_name,std::string&gt; file_name;
....
try
{
if( FILE * fp=fopen(“foo.txt”,”rt”) )
{
shared_ptr&lt;FILE&gt; f(fp,fclose);
....
read_file(fp); //throws types deriving from boost::<span class="RenoLink"><a href="exception.html">exception</a></span>
do_something();
....
}
else
throw file_open_error() <span class="RenoLink"><a href="exception_operator_shl.html">&lt;&lt;</a></span> errno_code(errno);
}
catch( boost::<span class="RenoLink"><a href="exception.html">exception</a></span> &amp; e )
{
e <span class="RenoLink"><a href="exception_operator_shl.html">&lt;&lt;</a></span> file_name(“foo.txt”);
throw;
}</pre>
<p>Finally here is how the handler retreives data from exceptions that derive from boost::<span class="RenoLink"><a href="exception.html">exception</a></span>:</p>
<pre>catch( io_error &amp; e )
{
std::cerr &lt;&lt; “I/O Error!\n”;
if( shared_ptr&lt;std::string const&gt; fn=<span class="RenoLink"><a href="get_error_info.html">get_error_info</a></span>&lt;file_name&gt;(e) )
std::cerr &lt;&lt; “File name: “ &lt;&lt; *fn &lt;&lt; “\n”;
if( shared_ptr&lt;int const&gt; c=<span class="RenoLink"><a href="get_error_info.html">get_error_info</a></span>&lt;errno_code&gt;(e) )
std::cerr &lt;&lt; “OS says: “ &lt;&lt; strerror(*c) &lt;&lt; “\n”;
}</pre>
</div><div class="RenoAutoDIV"><div class="RenoHR"><hr/></div>
<h3>See Also:</h3>
<div class="RenoPageList"><a href="boost-exception.html">Boost Exception<br/>
</a><a href="exception_types_as_simple_semantic_tags.html">Exception Types As Simple Semantic Tags<br/>
</a><a href="tutorial_enable_error_info.html">Integrating Boost Exception in Existing Exception Class Hierarchies<br/>
</a></div>
</div>
<!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. -->
<!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<div id="footer">
<p>&nbsp;</p>
<hr/>
<p>
<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>
<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>
<small>Copyright (c) 2006-2008 by Emil Dotchevski and Reverge Studios, Inc.<br/>
Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License, Version 1.0</a>.</small>
</p>
</div>
</div>
</div>
</div>
</body>
</html>

View File

@ -23,7 +23,6 @@
</div> </div>
<div class="RenoIndex"><h3>B</h3> <div class="RenoIndex"><h3>B</h3>
<p><a href="BOOST_THROW_EXCEPTION.html">BOOST_THROW_EXCEPTION</a></p> <p><a href="BOOST_THROW_EXCEPTION.html">BOOST_THROW_EXCEPTION</a></p>
<p><a href="boost-exception.html">Boost Exception</a></p>
<h3>b</h3> <h3>b</h3>
<p><a href="exception_hpp.html">boost/exception.hpp</a></p> <p><a href="exception_hpp.html">boost/exception.hpp</a></p>
<p><a href="exception_diagnostic_information_hpp.html">boost/exception/diagnostic_information.hpp</a></p> <p><a href="exception_diagnostic_information_hpp.html">boost/exception/diagnostic_information.hpp</a></p>
@ -45,6 +44,8 @@
<p><a href="tutorial_diagnostic_information.html">Diagnostic Information</a></p> <p><a href="tutorial_diagnostic_information.html">Diagnostic Information</a></p>
<h3>d</h3> <h3>d</h3>
<p><a href="diagnostic_information.html">diagnostic_information</a></p> <p><a href="diagnostic_information.html">diagnostic_information</a></p>
<h3>E</h3>
<p><a href="exception_types_as_simple_semantic_tags.html">Exception Types As Simple Semantic Tags</a></p>
<h3>e</h3> <h3>e</h3>
<p><a href="enable_current_exception.html">enable_current_exception</a></p> <p><a href="enable_current_exception.html">enable_current_exception</a></p>
<p><a href="enable_error_info.html">enable_error_info</a></p> <p><a href="enable_error_info.html">enable_error_info</a></p>
@ -60,8 +61,9 @@
<h3>g</h3> <h3>g</h3>
<p><a href="get_error_info.html">get_error_info</a></p> <p><a href="get_error_info.html">get_error_info</a></p>
<h3>I</h3> <h3>I</h3>
<p><a href="name_idx.html">Index</a></p>
<p><a href="tutorial_enable_error_info.html">Integrating Boost Exception in Existing Exception Class Hierarchies</a></p> <p><a href="tutorial_enable_error_info.html">Integrating Boost Exception in Existing Exception Class Hierarchies</a></p>
<h3>M</h3>
<p><a href="motivation.html">Motivation</a></p>
<h3>r</h3> <h3>r</h3>
<p><a href="rethrow_exception.html">rethrow_exception</a></p> <p><a href="rethrow_exception.html">rethrow_exception</a></p>
<h3>T</h3> <h3>T</h3>
@ -70,6 +72,8 @@
<h3>t</h3> <h3>t</h3>
<p><a href="throw_exception.html">throw_exception</a></p> <p><a href="throw_exception.html">throw_exception</a></p>
<p><a href="tuple_operator_shl.html">tuple/operator&lt;&lt;</a></p> <p><a href="tuple_operator_shl.html">tuple/operator&lt;&lt;</a></p>
<h3>U</h3>
<p><a href="using_virtual_inheritance_in_exception_types.html">Using Virtual Inheritance in Exception Types</a></p>
<h3>u</h3> <h3>u</h3>
<p><a href="unknown_exception.html">unknown_exception</a></p> <p><a href="unknown_exception.html">unknown_exception</a></p>
</div> </div>

File diff suppressed because it is too large Load Diff

View File

@ -53,6 +53,7 @@ my_container
</div><div class="RenoAutoDIV"><div class="RenoHR"><hr/></div> </div><div class="RenoAutoDIV"><div class="RenoHR"><hr/></div>
<h3>See Also:</h3> <h3>See Also:</h3>
<div class="RenoPageList"><a href="boost-exception.html">Boost Exception<br/> <div class="RenoPageList"><a href="boost-exception.html">Boost Exception<br/>
</a><a href="motivation.html">Motivation<br/>
</a></div> </a></div>
</div> </div>
<!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. --> <!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. -->

View File

@ -21,7 +21,11 @@
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<div class="RenoIncludeDIV"><div class="RenoAutoDIV"><h2>Transporting of Arbitrary Data to the Catch Site</h2> <div class="RenoIncludeDIV"><div class="RenoAutoDIV"><h2>Transporting of Arbitrary Data to the Catch Site</h2>
</div> </div>
<p>All exception types that derive from boost::<span class="RenoLink"><a href="exception.html">exception</a></span> can be used as type-safe containers of arbitrary data objects, while complying with the no-throw requirements (15.5.1) of the ANSI C++ standard for exception types. Data can be added to a boost::<span class="RenoLink"><a href="exception.html">exception</a></span> at the time of the throw, or at a later time.</p> <p>All exception types that derive from boost::<span class="RenoLink"><a href="exception.html">exception</a></span> can be used as type-safe containers of arbitrary data objects, while complying with the no-throw requirements (15.5.1) of the ANSI C++ standard for exception types.</p>
<p>When exceptions derive from boost::<span class="RenoLink"><a href="exception.html">exception</a></span>, arbitrary data can be added to exception objects:</p>
<div><ul><li>At the point of the throw;</li>
<li>At a later time as exceptions bubble up the call stack.</li>
</ul></div>
<div class="RenoIncludeDIV"><div class="RenoAutoDIV"><h3>Adding of Arbitrary Data at the Point of the Throw</h3> <div class="RenoIncludeDIV"><div class="RenoAutoDIV"><h3>Adding of Arbitrary Data at the Point of the Throw</h3>
</div> </div>
<p>The following example demonstrates how errno can be stored in exception objects using Boost Exception:</p> <p>The following example demonstrates how errno can be stored in exception objects using Boost Exception:</p>

View File

@ -0,0 +1,61 @@
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>using virtual inheritance in exception types</title>
<link href='reno.css' type='text/css' rel='stylesheet'/>
</head>
<body>
<div class="body-0">
<div class="body-1">
<div class="body-2">
<div>
<div id="boost_logo">
<a href="http://www.boost.org"><img style="border:0" src="http://www.boost.org/boost.png" alt="Boost" width="277" height="86"/></a>
</div>
<h1>Boost Exception</h1>
</div>
<!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. -->
<!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<div class="RenoIncludeDIV"><div class="RenoAutoDIV"><h3>Using Virtual Inheritance in Exception Types</h3>
</div>
<p>Exception types should use virtual inheritance when deriving from other exception types. This insight is due to Andrew Koenig. Using virtual inheritance prevents ambiguity problems in the exception handler:</p>
<pre>#include &lt;iostream&gt;
struct my_exc1 : std::exception { char const* what() const throw(); };
struct my_exc2 : std::exception { char const* what() const throw(); };
struct your_exc3 : my_exc1, my_exc2 {};
int
main()
{
try { throw your_exc3(); }
catch(std::exception const&amp; e) {}
catch(...) { std::cout &lt;&lt; "whoops!" &lt;&lt; std::endl; }
}</pre>
<p>The program above outputs "whoops!" because the conversion to std::exception is ambiguous.</p>
<p>The overhead introduced by virtual inheritance is always negligible in the context of exception handling. Note that virtual bases are initialized directly by the constructor of the most-derived-type (the type passed to the throw statement, in case of exceptions.) However, typically this detail is of no concern when boost::<span class="RenoLink"><a href="exception.html">exception</a></span> is used, because it enables exception types to be trivial structs with no members (there's nothing to initialize.) See <span class="RenoLink"><a href="exception_types_as_simple_semantic_tags.html">Exception Types As Simple Semantic Tags</a></span>.</p>
</div><div class="RenoAutoDIV"><div class="RenoHR"><hr/></div>
<h3>See Also:</h3>
<div class="RenoPageList"><a href="boost-exception.html">Boost Exception<br/>
</a></div>
</div>
<!-- Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc. -->
<!-- Distributed under the Boost Software License, Version 1.0. (See accompanying -->
<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
<div id="footer">
<p>&nbsp;</p>
<hr/>
<p>
<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>
<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>
<small>Copyright (c) 2006-2008 by Emil Dotchevski and Reverge Studios, Inc.<br/>
Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License, Version 1.0</a>.</small>
</p>
</div>
</div>
</div>
</div>
</body>
</html>