From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-02-10 00:54:47
"Geoff Leyland" <gley001_at_[hidden]> wrote in message
> 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
> 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
> *, something nicer might make things even easier.
> The question is: is this what Boost is about? Perhaps Boost
> be encouraging programming like this, perhaps some users of Boost
> 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:
s << "somebody made " << x << " mistakes";
This gives you the results you want, doesn't it? Is it really that
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk