# Boost Exception

## Diagnostic Information

Class boost::exception provides a virtual member function diagnostic_information, with a signature similar to the familiar std::exception::what function. The default implementation returns a string value that is not presentable as a friendly user message, but because it is generated automatically, it is useful for debugging or logging purposes. Here is an example:

    #include <boost/exception.hpp>
    #include <iostream>

    void f(); //throws unknown types that derive from boost::exception.

    void
    g()
        {
        try
            {
            f();
            }
        catch(
        boost::exception & e )
            {
            std::cerr << e.diagnostic_information();
            }
        }

The diagnostic_information member function iterates over all data objects stored in the boost::exception through operator<<. The returned string is constructed by converting each data object to string and then concatenating these strings together.

When the error_info<Tag,T> template is instantiated, the system attempts overload resolution for an unqualified call to to_string(x), where x is of type T. If this is successful, the to_string overload is expected to return std::string and is used to convert objects of type T to string.

Otherwise, the system attempts overload resolution for s << x, where s is a std::ostringstream and x is of type T. If this is successful, the operator<< overload is used to convert objects of type T to string.

Otherwise the system is unable to convert objects of type T to string, and an unspecified stub string value is used without issuing a compile error.

### See Also:

Boost Exception
exception::diagnostic_information