]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/exception/example/error_info_2.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 to add arbitrary data to active exception objects.
8 #include <boost/exception/all.hpp>
9 #include <boost/shared_ptr.hpp>
15 struct file_read_error
: virtual boost::exception
{ };
18 file_read( FILE * f
, void * buffer
, size_t size
)
20 if( size
!=fread(buffer
,1,size
,f
) )
21 throw file_read_error() << boost::errinfo_errno(errno
);
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
);
30 parse_file( char const * file_name
)
32 boost::shared_ptr
<FILE> f
= file_open(file_name
,"rb");
37 file_read( f
.get(), buf
, sizeof(buf
) );
40 boost::exception
& e
)
42 e
<< boost::errinfo_file_name(file_name
);