Boost logo

Boost :

Subject: Re: [boost] expected/result/etc
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2016-02-13 16:58:23


On Fri, Feb 12, 2016 at 11:50 PM, Michael Marcin <mike.marcin_at_[hidden]>
wrote:

> On 2/13/2016 12:08 AM, Emil Dotchevski wrote:
>
>>
>> If your point is that in case a function "fails" 50% of the times it's
>> called, one should not be throwing an exception to discriminate between
>> success and failure, I agree; OTOH in this case the "error code"
>> vocabulary
>> doesn't seem appropriate.
>>
>>
> If instead I told you I had a function that is called 100k times per frame
> and that function returns an error code 1% of the time, would it make more
> sense?
> It returns a result<T> that holds a T 99% of the time.
>
> I don't think you would advocate throwing 1000 exceptions a frame.

I don't normally base my decision to throw or to not throw on performance
considerations, and it's not a matter of statistical analysis. Let's say
you have a function that returns objects, and that the objects can be one
of two colors, red and white. The function probably shouldn't use
exceptions to communicate red color even if in a given sample 99% of the
objects are white. On the other hand, if attempting to use a red object is
always an error, then red should be communicated by throwing, even if most
of the objects are red, so that the caller can assume he will get a good
object, or the function won't return.

Emil


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