I\'m trying to following the examples on this page:
http://www.boost.org/doc/libs/1_40_0/libs/exception/doc/motivation.html
The minute I try the following li
try:
#include <boost/exception/error_info.hpp>
#include <errno.h>
throw file_read_error() << boost::errinfo_errno(errno);
even better:
BOOST_THROW_EXCEPTION(file_read_error() << errinfo_errno(errno));
Your HRESULTErrorInfo example seems correct.
Sam Miller gave me a clue as to what the problem was. I just needed to include:
#include <boost/exception/all.hpp>
Thanks for your answers.
#include <boost/exception/all.hpp>
#include <boost/throw_exception.hpp>
#include <iostream>
#include <stdexcept>
#include <string>
typedef boost::error_info<struct my_tag,std::string> my_tag_error_info;
int
main()
{
try {
boost::throw_exception(
boost::enable_error_info( std::runtime_error( "some error" ) )
<< my_tag_error_info("my extra info")
);
} catch ( const std::exception& e ) {
std::cerr << e.what() << std::endl;
if ( std::string const * extra = boost::get_error_info<my_tag_error_info>(e) ) {
std::cout << *extra << std::endl;
}
}
}
produces
samm@macmini> ./a.out
some error
my extra info