mirror of
https://github.com/boostorg/exception.git
synced 2025-07-12 12:06:33 +02:00
63 lines
3.3 KiB
HTML
63 lines
3.3 KiB
HTML
<!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>Tutorial: Adding Grouped Data to Exceptions</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>
|
|
<div class="RenoIncludeDIV"><h3>Adding Grouped Data to Exceptions</h3>
|
|
<p>The code snippet below demonstrates how <tt>boost::<span class="RenoLink"><a href="http://www.boost.org/libs/tuple/doc/tuple_users_guide.html">tuple</a></span></tt> can be used to bundle the name of the function that failed, together with the reported <tt>errno</tt> so that they can be added to exception objects more conveniently together:</p>
|
|
<pre>#include <<span class="RenoLink"><a href="exception_error_info_group_hpp.html">boost/exception/info_tuple.hpp</a></span>>
|
|
#include <boost/shared_ptr.hpp>
|
|
#include <stdio.h>
|
|
#include <string>
|
|
#include <errno.h>
|
|
|
|
typedef boost::<span class="RenoLink"><a href="error_info.html">error_info</a></span><struct tag_file_name,std::string> file_name_info;
|
|
typedef boost::<span class="RenoLink"><a href="error_info.html">error_info</a></span><struct tag_function,char const *> function_info;
|
|
typedef boost::<span class="RenoLink"><a href="error_info.html">error_info</a></span><struct tag_errno,int> errno_info;
|
|
typedef boost::tuple<function_info,errno_info> clib_failure;
|
|
|
|
class file_open_error: public boost::<span class="RenoLink"><a href="exception.html">exception</a></span> { };
|
|
|
|
boost::shared_ptr<FILE>
|
|
file_open( char const * name, char const * mode )
|
|
{
|
|
if( FILE * f=fopen(name,mode) )
|
|
return boost::shared_ptr<FILE>(f,fclose);
|
|
else
|
|
throw file_open_error() <<
|
|
file_name_info(name) <<
|
|
clib_failure("fopen",errno);
|
|
}</pre>
|
|
<p>Note that the members of a <tt>boost::<span class="RenoLink"><a href="http://www.boost.org/libs/tuple/doc/tuple_users_guide.html">tuple</a></span></tt> are stored separately in exception objects; they can only be retrieved individually, using <tt><span class="RenoLink"><a href="get_error_info.html">get_error_info</a></span>()</tt>.</p>
|
|
</div><h3>See also:</h3>
|
|
<div class="RenoPageList"><a href="transporting_data.html">Tutorial: Transporting of Arbitrary Data to the Catch Site<br/>
|
|
</a></div>
|
|
<div id="footer">
|
|
<p> </p>
|
|
<hr/>
|
|
<p>
|
|
<a class="logo" href="http://jigsaw.w3.org/css-validator/validator?uri=http://revergestudios.com/boost-exception/reno.css"><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>
|