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 enable cloning when throwing a boost::exception. 7 8 #include <boost/exception/info.hpp> 9 #include <boost/exception/errinfo_errno.hpp> 10 #include <stdio.h> 11 #include <errno.h> 12 13 struct file_read_error: virtual boost::exception { }; 14 15 void file_read(FILE * f,void * buffer,size_t size)16file_read( FILE * f, void * buffer, size_t size ) 17 { 18 if( size!=fread(buffer,1,size,f) ) 19 throw boost::enable_current_exception(file_read_error()) << 20 boost::errinfo_errno(errno); 21 } 22