Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Boost Exception


#include <boost/exception/info.hpp>

    template <class Tag,class T>
        typedef T value_type;    
        error_info( value_type const & v );    
        value_type const & value() const;
        value_type & value();    


T must have accessible copy constructor and must not be a reference (there is no requirement that T's copy constructor does not throw.)


This class template is used to associate a Tag type with a value type T. Objects of type error_info<Tag,T> can be passed to operator<< to be stored in objects of type boost::exception.


The header <boost/exception/error_info.hpp> provides a declaration of the error_info template, which is sufficient for the purpose of typedefing an instance for specific Tag and T, for example:

#include <boost/exception/error_info.hpp>

struct tag_errno;
typedef boost::error_info<tag_errno,int> errno_info;

Or, the shorter equivalent:

#include <boost/exception/error_info.hpp>

typedef boost::error_info<struct tag_errno,int> errno_info;

This errno_info typedef can be passed to operator<< (#include <boost/exception/info.hpp> first) to store an int named tag_errno in exceptions of types that derive from boost::exception:

throw file_read_error() << errno_info(errno);

It can also be passed to get_error_info (#include <boost/exception/get_error_info.hpp> first) to retrieve the tag_errno int from a boost::exception:

catch( boost::exception & x )
    if( int const * e=boost::get_error_info<errno_info>(x) )

For convenience and uniformity, Boost Exception defines the following commonly used error_info typedefs, ready for use with operator<<: