From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2006-08-21 13:07:13
I just finished an update to the exception library I am planning to propose
for addition to Boost. I appreciate all feedback, including incompatibility
reports with various compilers (I believe the implementation to be
standard-conforming, but I have only tested with msvc 7.1/8.0 and gcc
As usual, the latest documentation is here:
Here is a zip file with the source code, complete with jamfiles and tests:
Here's what's new in this update: class boost::exception now defines what()
function, similarly to std::exception. It automatically formats a message
which combines all exception info stored by operator<< in the
boost::exception object. The message is not user-friendly; it is designed
for dumping in log files and for other debugging systems.
For what() to work, the system needs to be able to convert the exception
info values stored in a boost::exception to string. Because this is not a
critical feature, I thought it wouldn't be a good idea to require the user
code to provide such a conversion for everything. The current implementation
generates a string representation of each exception info value (at the time
exception_info is called) as follows:
- If a suitable overload for the unqualified call to to_string (passing the
exception info value as the only argument) is found, that overload is used.
- Otherwise, if a suitable overload for serializing the exception info value
into a std::ostringstream is found, that overload is used.
- Otherwise the system gives up and uses a generic "stub" string to indicate
that the exception info value could not be converted to string.
This is accomplished through the to_string function template, which has the
template <class T>
std::string to_string( T const &, char const * stub );
Do you think that to_string is universally useful? Is there anything in
Boost with similar functionality? Perhaps we can make to_string a separate
addition to Boost?