|
Boost : |
Subject: Re: [boost] [C++11] If you have an old class with a throwingdestructor...
From: Peter Dimov (lists_at_[hidden])
Date: 2013-09-16 17:51:27
Emil Dotchevski wrote:
> On Mon, Sep 16, 2013 at 1:47 PM, Eric Niebler <eniebler_at_[hidden]> wrote:
> > On 9/16/2013 2:20 AM, Nathan Ridge wrote:
> >>> On 13-09-09 02:57 PM, Niall Douglas wrote:
> >>>> On 9 Sep 2013 at 13:11, Nevin Liber wrote:
> >>>>
> >>>>>> In C++03 it was always best practice to *always* wrap your
> >>>>>> destructors in a try...catch clause.
> >>>>>
> >>>>> No; the best practice is not to throw from a destructor.
> >>>>
> >>>> Sorry, my unclear phrasing again ... by wrapping destructors I
> >>>> specifically meant:
> >>>>
> >>>> destructor::~destructor()
> >>>> { try {
> >>>> ...
> >>>> } catch(...) { /* do something useful */ } }
> >>>
> >>> Can you elaborate on what "something useful" is in this context?
> >>
> >> Log the error, perhaps?
> >
> > Sure. And then? Don't say, "Quietly swallow the exception." Something
> > Very Bad has happened.
>
> Nothing bad has happened. If something can fail "badly" you shouldn't
> do it in the destructor.
Or at all. "Very Bad" means "no exception safety guarantee", which is
another way of saying "do not use".
Stated differently, if the ... throwing is Very Bad, it would still be Very
Bad if used outside of a destructor. So you shouldn't ever use it.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk