Boost logo

Boost :

From: Ed Brey (brey_at_[hidden])
Date: 2000-06-05 14:52:34


From: "Mark Rodgers" <mark.rodgers_at_[hidden]>
> I feel that exceptions should be avoidable, so if there isn't some
> mechanism for a silent failure, then there should be an easy way for
> you to test whether an exception would be thrown:

What's benefit do you see in avoiding exceptions? From a programming
point of view:

> std:string s;
> ...
> if (is_a<double>(foo))
> {
> double d = stream_cast<double>(foo);
> ...
> }
> else
> {
> // do something else...
> }

is very close to

std::string foo;

try
{
    double d = stream_cast<double>(foo);
    ...
}
catch (const ios::failure&) // or whatever exception we choose
{
    // do something else...
}

Returning default values on failure is ambiguous, unless you know from
your context that the default would be impossible. The throwing
version should be very fast, definitely better than the is_a approach,
which needs to parse the string twice.

There is a cost to having more choices, and so the benefit of having a
nothrowing version would have to be at least as high.


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