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
15struct file_read_error: virtual boost::exception { };
16
17void
18file_read( FILE * f, void * buffer, size_t size )
19 {
20 if( size!=fread(ptr: buffer,size: 1,n: size,stream: f) )
21 throw file_read_error() << boost::errinfo_errno(errno);
22 }
23
24//
25
26boost::shared_ptr<FILE> file_open( char const * file_name, char const * mode );
27void file_read( FILE * f, void * buffer, size_t size );
28
29void
30parse_file( char const * file_name )
31 {
32 boost::shared_ptr<FILE> f = file_open(file_name,mode: "rb");
33 assert(f);
34 try
35 {
36 char buf[1024];
37 file_read( f: f.get(), buffer: buf, size: sizeof(buf) );
38 }
39 catch(
40 boost::exception & e )
41 {
42 e << boost::errinfo_file_name(file_name);
43 throw;
44 }
45 }
46

source code of boost/libs/exception/example/error_info_2.cpp