🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Exceptions in derived class destructors

#2680
From: Fergus Henderson
Date: Tue, 21 Nov 1995 15:47
39 lines
2506 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:
>
>  If a derived class destructor throws an exception, do member and base
>  class destructors still get called? 

If you are asking about what the current working paper says, I'm not sure
off-hand.  If you are asking about what the working paper *should* say,
then I think the answer should be yes, member and base class destructors
should still get called.  Otherwise the destructor would have to catch
execptions and manually destroy the bases and members before rethrowing
to avoid resource leaks.  This would be extremely tedious coding,
and would be extremely difficult - probably totally impractical - in the
case of virtual inheritence.

>  My feeling is
>  the answer should be no, in the same way that the remainder of D's
>  destructor is not executed after the throw.

I disagree.  The answer should be yes, in the same way that bases
and members are destroyed if an exception occurs in the constructor.

Any class which attempts to manage more than one resource must be
careful do its own recovery if an exception occurs after constructing
or destroying a subset of those resources.  But for a class which
merely aggregates different resources which are managed by members or
base classes, the author of that class should not have to worry about
exception handling.

--
Fergus Henderson             	WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au              	PGP: finger fjh@128.250.37.3
---
[ 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: <9511211402.3271@mulga.cs.mu.OZ.AU>
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <smeyersDI7uqr.9vt@netcom.com>

Show Full Headers
Complete Article Headers
Approved: fjh@cs.mu.oz.au
Date: 21 Nov 95 15:47:14 GMT
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Message-ID: <9511211402.3271@mulga.cs.mu.OZ.AU>
Newsgroups: comp.std.c++
Organization: Computer Science, University of Melbourne, Australia
Path: arc1-ca.pugleaf.net!in1.uu.net!bounce-back
References: <smeyersDI7uqr.9vt@netcom.com>
Subject: Re: Exceptions in derived class destructors
X-Original-Date: Tue, 21 Nov 1995 14:01:55 GMT
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMLH0meEDnX0m9pzZAQHIywF/Wda8rvnaqsbaZvtK3GKe0p6PMBjzQFph
 d2FBPK9zCtJi6DX7Yz36kqh5nVgxMw0U
 =EaC9