Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-02-10 00:54:47


"Geoff Leyland" <gley001_at_[hidden]> wrote in message
news:D6E59621-5B82-11D8-B48C-000A95DB9BF6_at_ec.auckland.ac.nz...
> On 10/02/2004, at 5:00 PM, Jonathan Turkanis wrote:

> Throwing a streamy exception has small advantages over a const char
*
> (you can add more information) and an ostringstream (you can catch
it
> as a std::exception) and it lends itself to further extension.

Definitely! Throwing a const char* is always a bad idea, since no one
expects to catch a const char*, and even if you write a const char*
handler there's no way to tell in advance that you will be able to
handle the error represented by the const char*. In general, you
cannot throw a stringstream, since streams need not be copyable.

> > For small programs written by one person these issues are not so
> > important. (These are also the cases where you can get away with
> > thowing int or const char* ;-)
>
> Yes. And in cases where you might get away with an int or const
char
> *, something nicer might make things even easier.

> The question is: is this what Boost is about? Perhaps Boost
shouldn't
> be encouraging programming like this, perhaps some users of Boost
are
> writing clunky command like computational code.

I think boost should encourage best practices, not practices which
work acceptably only in limited circumstances without providing
substantial benefits. For miscellaneous errors, you can use one the
standard exception classes, such as runtime_error, using a
stringstream to format the results, if you like:

     stringstream s;
     s << "somebody made " << x << " mistakes";
     throw runtime_error(s.str());

This gives you the results you want, doesn't it? Is it really that
inconvenient?

Jonathan


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