]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/exception/example/error_info_2.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / exception / example / error_info_2.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 to add arbitrary data to active exception objects.
7
8 #include <boost/exception/all.hpp>
9 #include <boost/shared_ptr.hpp>
10 #include <stdio.h>
11 #include <errno.h>
12
13 //
14
15 struct file_read_error: virtual boost::exception { };
16
17 void
18 file_read( FILE * f, void * buffer, size_t size )
19 {
20 if( size!=fread(buffer,1,size,f) )
21 throw file_read_error() << boost::errinfo_errno(errno);
22 }
23
24 //
25
26 boost::shared_ptr<FILE> file_open( char const * file_name, char const * mode );
27 void file_read( FILE * f, void * buffer, size_t size );
28
29 void
30 parse_file( char const * file_name )
31 {
32 boost::shared_ptr<FILE> f = file_open(file_name,"rb");
33 assert(f);
34 try
35 {
36 char buf[1024];
37 file_read( f.get(), buf, sizeof(buf) );
38 }
39 catch(
40 boost::exception & e )
41 {
42 e << boost::errinfo_file_name(file_name);
43 throw;
44 }
45 }