Boost logo

Boost :

From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2006-08-23 14:20:20


Gerhard Wesp wrote:
> On Wed, Aug 23, 2006 at 10:39:35AM -0700, Emil Dotchevski wrote:
>> addition to boost, and the what() function of class
>> boost::exception. You're probably thinking about
>> std::exception::what(), which is different.
>
> I see. Indeed I was confusing the two.
>
>> named it what() because its purpose is very similar: to identify the
>> exception (info stored in the exception) object, not to format a
>> message for the user.
>
> Still, I *do* use the what() string in std::exception to format a
> message for the user, and this turns out to work pretty well. AFAIK,
> the standard doesn't assign a purpose to the what() string---It is
> what it is, a string held by the exception object.

If I understand you correctly, you are storing a user message in the
exception when you throw it, and then use std::exception::what() to retrieve
it, right? This approach is problematic for several reasons, most notably
because the user message has to be localized, but also because different
programs may need to output different messages in response to the same
exception thrown by a shared library.

The job of the exception object is not to format a user message, but to
deliver enough information to the catch site so that it can format a user
message.

About std::exception::what(), until recently I was implementing it in my
base exception class as "return typeid(*this).name()". Since I converted all
of my code to use the proposed boost exception library, my base exception
class derives virtually from std::exception and virtually from
boost::exception, and is implemented as "return boost::exception::what()". I
am playing with the idea to add the typeid(*this).name() as part of the
non-user-friendly string formatted by boost::exception::what().

--Emil Dotchevski


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk