Boost logo

Boost :

Subject: Re: [boost] Noexcept
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2017-06-29 17:26:21


On Wed, Jun 28, 2017 at 11:34 PM, Andrzej Krzemienski via Boost <
boost_at_[hidden]> wrote:

> 2017-06-29 8:14 GMT+02:00 Emil Dotchevski via Boost <boost_at_[hidden]
> >:
>
> > On Wed, Jun 21, 2017 at 12:43 AM, Andrzej Krzemienski via Boost <
> > boost_at_[hidden]> wrote:
> >
> > > > In error-neutral contexts, you simply return throw_() to propagate
> any
> > > > error from lower level functions.
> > >
> > > But does this not compromise exception neutrality? That you have to
> > specify
> > > in each function that you want to just pass the exception up?
> >
> > Compared to what? Is there a better option when you can't throw?
>
> My observation is, if you cannot throw then exception neutrality is not
> achievable.
>

In functions that propagate errors in the return value (very common both in
C and in -fno-exceptions C++), each caller has to take the returned error
code, examine it, then possibly return a copy of it -- but it is also
common to return another error, which is known as error translation (which
is a bad idea).

Instead, functions which can't handle the error should just propagate it to
the caller. That is what it means to be neutral: "I don't know what this
is, someone else please deal with it". In Noexcept neutrality can be
expressed explicitly: you simply return throw_(), which doesn't touch the
error object at all.

> Here, by "exception neutrality" I mean what function std::qsort is doing.
>

I would not bet that qsort is exception-safe on all platforms.

Emil


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