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>errinfo_api_function</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"><h3>errinfo_api_function</h3> 23</div> 24<div class="RenoIncludeDIV"><p><span class="RenoEscape">#<!--<wiki>`#</wiki>--></span>include <<span class="RenoLink"><a href="boost_exception_errinfo_api_function_hpp.html">boost/exception/errinfo_api_function.hpp</a></span>></p> 25<div class="RenoIncludeDIV"><pre>#include <<span class="RenoLink"><a href="boost_exception_error_info_hpp.html">boost/exception/error_info.hpp</a></span>> 26 27namespace 28boost 29 { 30<span class="RenoIncludeSPAN"> <span class="RenoIncludeSPAN">typedef <span class="RenoLink"><a href="error_info.html">error_info</a></span><struct errinfo_api_function_,char const *> <span class="RenoLink">errinfo_api_function</span>;</span></span> 31 }</pre> 32</div></div><p>This type is designed to be used as a standard <span class="RenoLink"><a href="error_info.html">error_info</a></span> instance for transporting the name of a relevant API function (which does not use exceptions to report errors) in exceptions deriving from boost::<span class="RenoLink"><a href="exception.html">exception</a></span>.</p> 33<h3>Example:</h3> 34<div class="RenoIncludeDIV"><pre>#include <<span class="RenoLink"><a href="boost_exception_errinfo_api_function_hpp.html">boost/exception/errinfo_api_function.hpp</a></span>> 35#include <<span class="RenoLink"><a href="boost_exception_errinfo_at_line_hpp.html">boost/exception/errinfo_at_line.hpp</a></span>> 36#include <<span class="RenoLink"><a href="boost_exception_errinfo_errno_hpp.html">boost/exception/errinfo_errno.hpp</a></span>> 37#include <<span class="RenoLink"><a href="boost_exception_errinfo_file_handle_hpp.html">boost/exception/errinfo_file_handle.hpp</a></span>> 38#include <<span class="RenoLink"><a href="boost_exception_errinfo_file_name_hpp.html">boost/exception/errinfo_file_name.hpp</a></span>> 39#include <<span class="RenoLink"><a href="boost_exception_errinfo_file_open_mode_hpp.html">boost/exception/errinfo_file_open_mode.hpp</a></span>> 40#include <<span class="RenoLink"><a href="boost_exception_info_hpp.html">boost/exception/info.hpp</a></span>> 41#include <<span class="RenoLink"><a href="boost_throw_exception_hpp.html">boost/throw_exception.hpp</a></span>> 42#include <boost/shared_ptr.hpp> 43#include <boost/weak_ptr.hpp> 44#include <stdio.h> 45#include <errno.h> 46#include <exception> 47 48struct error : virtual std::exception, virtual boost::<span class="RenoLink"><a href="exception.html">exception</a></span> { }; 49struct file_error : virtual error { }; 50struct file_open_error: virtual file_error { }; 51struct file_read_error: virtual file_error { }; 52 53boost::shared_ptr<FILE> 54open_file( char const * file, char const * mode ) 55 { 56 if( FILE * f=fopen(file,mode) ) 57 return boost::shared_ptr<FILE>(f,fclose); 58 else 59 <span class="RenoLink"><a href="BOOST_THROW_EXCEPTION.html">BOOST_THROW_EXCEPTION</a></span>( 60 file_open_error() << 61 boost::<span class="RenoLink">errinfo_api_function</span>("fopen") << 62 boost::<span class="RenoLink"><a href="errinfo_errno.html">errinfo_errno</a></span>(errno) << 63 boost::<span class="RenoLink"><a href="errinfo_file_name.html">errinfo_file_name</a></span>(file) << 64 boost::<span class="RenoLink"><a href="errinfo_file_open_mode.html">errinfo_file_open_mode</a></span>(mode) ); 65 } 66 67size_t 68read_file( boost::shared_ptr<FILE> const & f, void * buf, size_t size ) 69 { 70 size_t nr=fread(buf,1,size,f.get()); 71 if( ferror(f.get()) ) 72 <span class="RenoLink"><a href="BOOST_THROW_EXCEPTION.html">BOOST_THROW_EXCEPTION</a></span>( 73 file_read_error() << 74 boost::<span class="RenoLink">errinfo_api_function</span>("fread") << 75 boost::<span class="RenoLink"><a href="errinfo_errno.html">errinfo_errno</a></span>(errno) << 76 boost::<span class="RenoLink"><a href="errinfo_file_handle.html">errinfo_file_handle</a></span>(f) ); 77 return nr; 78 }</pre> 79</div></div><div class="RenoAutoDIV"><div class="RenoHR"><hr/></div> 80See also: <span class="RenoPageList"><a href="boost_exception_errinfo_api_function_hpp.html">boost/exception/errinfo_api_function.hpp</a> | <a href="frequently_asked_questions.html">Frequently Asked Questions</a></span> 81</div> 82<!-- Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc. --> 83<!-- Distributed under the Boost Software License, Version 1.0. (See accompanying --> 84<!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> 85<div id="footer"> 86<p> 87<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> 88<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> 89<small>Copyright (c) 2006-2009 by Emil Dotchevski and Reverge Studios, Inc.<br/> 90Distributed under the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License, Version 1.0</a>.</small> 91</p> 92</div> 93</div> 94</div> 95</div> 96</body> 97</html> 98