cloning_1.cpp 689 B

123456789101112131415161718192021
  1. //Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
  2. //Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. //file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. //This example shows how to enable cloning when throwing a boost::exception.
  5. #include <boost/exception/info.hpp>
  6. #include <boost/exception/errinfo_errno.hpp>
  7. #include <stdio.h>
  8. #include <errno.h>
  9. struct file_read_error: virtual boost::exception { };
  10. void
  11. file_read( FILE * f, void * buffer, size_t size )
  12. {
  13. if( size!=fread(buffer,1,size,f) )
  14. throw boost::enable_current_exception(file_read_error()) <<
  15. boost::errinfo_errno(errno);
  16. }