|
Boost : |
Subject: Re: [boost] [outcome] "sea of noexcept, islands of throwing"
From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2017-01-17 12:59:13
>> If yes, there comes another question. One of the main reasons exceptions
>> were introduced in the first place was to be able to report failures
>> from
>> functions that cannot use the return value for this purpose:
>> constructors,
>> conversion operators, and other operators. How do you deal with these
>> functions in the sea of noexcept?
>
> I would argue that failing to create an object is breaking so many
> invariants that this awards an exception. On the other hand, we do have
> an example of objects which can be constructed in a failed state, e.g.
> std::ifstream which then come with their own error reporting mechanism.
It's definitely a rich source of bugs to handle constructors which throw
correctly. It's safer to make constructors very simple forwarding only
affairs and construct their contents from a static init function such
that the only way you can publicly construct such a class is exclusively
via its static init function.
Niall
-- ned Productions Limited Consulting http://www.nedproductions.biz/ http://ie.linkedin.com/in/nialldouglas/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk