...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Boost Exception provides a namespace-scope function diagnostic_information which takes a boost::exception. The returned string contains:
The returned string 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/all.hpp> #include <iostream> void f(); //throws unknown types that derive from boost::exception. void g() { try { f(); } catch( boost::exception & e ) { std::cerr << diagnostic_information(e); } }
this is a possible output from the diagnostic_information function, as used in libs/exception/example/example_io.cpp:
example_io.cpp(70): Throw in function class boost::shared_ptr<struct _iobuf> __cdecl my_fopen(const char *,const char *) Dynamic exception type: class boost::exception_detail::clone_impl<struct fopen_error> std::exception::what: example_io error [struct boost::errinfo_api_function_ *] = fopen [struct boost::errinfo_errno_ *] = 2, "No such file or directory" [struct boost::errinfo_file_name_ *] = tmp1.txt [struct boost::errinfo_file_open_mode_ *] = rb