🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2647

Re: Exceptions in derived class destructors

#2647
From: Steve Clamage
Date: Sun, 19 Nov 1995 02:59
39 lines
2253 bytes
smeyers@netcom.com (Scott Meyers) writes:

>I posted this a while ago as part of a larger posting, but nobody ever
>responded.  I'm reposting it as a separate question in hope of gaining
>insight into the proper behavior of destructors when exceptions are thrown:

>  ...

>  When d is destroyed, D's destructor throws.  Are destructors
>  nevertheless called for d.D::m, the B part of d, and d.B::m?  My feeling is
>  the answer should be no, ...

The draft says that when an exception is thrown, control is transferred
to the handler for that exception, or to the terminate function if
there is no handler.

I don't see how to interpret that to allow any additional processing if
the destructor exits via an exception.

The special cases of operator new or a constructor exiting via an
exception as part of a new-expression has some additional handling,
but I don't see any special cases for destructors.

In other words, the base-class destructors should not be run. LOTS
of things about exceptions have needed clarification or changes
in the rules, so it wouldn't be surprising to see variation in
compiler behavior right now.

Apart from all of that, it is unlikely to be a good idea to throw
an exception from a destructor. It would be safer and less likely
to leave the program in an unknown state to use some other error-
reporting method for destructors.

--
Steve Clamage, stephen.clamage@eng.sun.com

[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <48m6b8$2ll@engnews1.eng.sun.com>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
References: <smeyersDI7uqr.9vt@netcom.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
From: clamage@Eng.sun.com (Steve Clamage)
Newsgroups: comp.std.c++
Subject: Re: Exceptions in derived class destructors
Date: 19 Nov 1995 02:59:52 GMT
Organization: Sun Microsystems Inc., Mountain View, CA
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <48m6b8$2ll@engnews1.eng.sun.com>
References: <smeyersDI7uqr.9vt@netcom.com>
NNTP-Posting-Host: taumet.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: taumet.eng.sun.com
X-Newsreader: NN version 6.5.0 #21 (NOV)
Content-Length: 1411
Originator: clamage@taumet