Boost logo

Boost :

From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2000-06-06 02:34:46

From: Ed Brey <brey_at_[hidden]>

> What's benefit do you see in avoiding exceptions?

I don't think exceptions should be used as a normal control
mechanism; they should be reserved for exceptional circumstances.
AFAIK, the costs of throwing an exception are quite high, and
are not something we want to have to pay for regularly.

> Returning default values on failure is ambiguous, unless you
> know from your context that the default would be impossible.

Agreed. But sometimes we may indeed know this:

      int n = stream_cast<int>(argv[1], 0);
      if (n < 5)
          std::cerr << "x must be a number greater than 4.";
          return EXIT_FAILURE;

Do we care whether the user typed "fred" or "3"? Possibly not.

> The
> throwing version should be very fast, definitely better than the
> is_a approach, which needs to parse the string twice.

Absolutely true. That's why I probably prefer the default value
approach. As I understand it, the initial version returned a
default value anyway, but with no way to specify what that default
was. I think this can be improved by allowing the client to
specify the default value, and using its presence as the way of
suppressing exceptions. We can then add the throwing overload
that some people want.


Boost list run by bdawes at, gregod at, cpdaniel at, john at