]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/exception/example/info_tuple.cpp
1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
3 //Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //This example shows how boost::tuple can be used to bundle the
7 //name of the function that fails together with the reported errno.
9 #include <boost/exception/info_tuple.hpp>
10 #include <boost/exception/errinfo_file_name.hpp>
11 #include <boost/exception/errinfo_api_function.hpp>
12 #include <boost/exception/errinfo_errno.hpp>
13 #include <boost/shared_ptr.hpp>
18 typedef boost::tuple
<boost::errinfo_api_function
,boost::errinfo_errno
> clib_failure
;
20 struct file_open_error
: virtual boost::exception
{ };
22 boost::shared_ptr
<FILE>
23 file_open( char const * name
, char const * mode
)
25 if( FILE * f
=fopen(name
,mode
) )
26 return boost::shared_ptr
<FILE>(f
,fclose
);
28 throw file_open_error() <<
29 boost::errinfo_file_name(name
) <<
30 clib_failure("fopen",errno
);