|
Boost : |
From: Bertolt Mildner (Bertolt.Mildner_at_[hidden])
Date: 2000-06-06 13:29:24
----- Original Message -----
From: "Mark Rodgers" <mark.rodgers_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, June 06, 2000 9:34 AM
Subject: Re: [boost] Plea for addition of stream_cast
> 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.
I agree, but hence converting "Fred" in an object of type float is nothing normal I thing we should go for the throwing version of stream_cast.
> > 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.
But what if there is no value that can be used as a return value in case if an error?
An other point I want to mention is that I feel that stream_cast should do what standard casts like dynamic_cast do in case of an unrecoverable error, throwing an object of typ std::bad_cast.
Bertolt
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk