Boost logo

Boost :

Subject: Re: [boost] expected/result/etc
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2016-02-11 02:19:04


On 2/9/2016 3:16 AM, Niall Douglas wrote:
>
> Something missing from the discussion so far is that
> expected/result/outcome MUST throw exceptions! If you try to fetch a
> value from a result and it contains an error, there is no alternative
> to throwing an exception. This fact is why I don't worry about static
> function initialisers and just go ahead and use
> error-code-via-system_error throwing constructors, ultimately you
> need try...catch in there one way or another.
>

There most certainly is an alternative!
I certainly don't want this behavior.

There's no way that accessing the value of a result<T> without checking
for an error is not a programming error.
It should be a precondition that to access the value it needs to not
contain an error.
It should *not* be throwing an exception because you cannot fail to
satisfy the postcondition until you meet the preconditions.

Undefined-behavior is the appropriate specification for accessing a
value from a result that contains an error.


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