]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/exception/example/info_tuple.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / exception / example / info_tuple.cpp
1 //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
2
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)
5
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.
8
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>
14 #include <stdio.h>
15 #include <string>
16 #include <errno.h>
17
18 typedef boost::tuple<boost::errinfo_api_function,boost::errinfo_errno> clib_failure;
19
20 struct file_open_error: virtual boost::exception { };
21
22 boost::shared_ptr<FILE>
23 file_open( char const * name, char const * mode )
24 {
25 if( FILE * f=fopen(name,mode) )
26 return boost::shared_ptr<FILE>(f,fclose);
27 else
28 throw file_open_error() <<
29 boost::errinfo_file_name(name) <<
30 clib_failure("fopen",errno);
31 }