|
Boost : |
Subject: Re: [boost] expected/result/etc
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2016-02-11 18:33:04
On Thu, Feb 11, 2016 at 3:17 PM, Bjorn Reese <breese_at_[hidden]>
wrote:
> On 02/11/2016 11:57 PM, Emil Dotchevski wrote:
>
> failure, and others that do not, without giving the user a choice. Even at
>> the language level, consider that in C++ constructors don't give you the
>> option to return an error code, the only way for them to fail is by
>> throwing. Why? Because that is the correct design.
>>
>
> True. However, there are situations where throwing exceptions is the
> wrong design, like continuations (e.g. future<T>::then) or asynchronous
> return values (e.g. Boost.Asio handlers.) For both the situations a
> value-or-error type, like excepted<T>, is a correct design.
Obviously there are such situations when throwing is the wrong design. In
C++ there are three options in case of errors:
1) undefined behavior (e.g. assert)
2) report the error to the caller
3) throw
Choosing the correct behavior(s) is not always trivial, but "oh, I'll let
the user choose what's best for him" is not good design.
Emil
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk