🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Exceptions in derived class destructors

#2668
From: Steve Clamage
Date: Tue, 21 Nov 1995 15:58
54 lines
2828 bytes
Dick Menninger <Dick.Menninger@daytonoh.attgis.com> writes:

>> ==========Steve Clamage, 11/18/95==========
>> 
>> 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.

>In some cases, it would seem that not allowing exceptions
>to be thrown from destructors would be problematic rather
>than helpful.  ...
>I do not see why destructors are seen as poor stepchildren
>relative to all other contexts.

But destructors ARE special as regards exceptions. On the way to
finding a handler, auto objects are destroyed. If the destructor
of an auto object exits via an exception while unwinding back to a
handler, the program terminates.

You can exit a destructor via an exception safely only if you know
that no exception is in the process of being handled, or if you
know that the current object is not auto. If you could know
those things, and if you could write code like
	if( safe_to_throw )
	    throw X;
	else
	    do_something_else;
you might just as well do_something_else all the time -- and use
a different mechanism to handle the exceptional condition.


This view will make for a basic
>inconsistency in the language.  The rules must be more uniform
>or they will make a mess of it.  You have to continue to
>destruct pieces in reverse order.  Throwing an exception
>in a destructor is merely a special return from that piece of
>destruction analogous to the constructor case.

>To the contrare.

>Good Day
>Dick
>Dick.Menninger@DaytonOH.ATTGIS.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. ]
--
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: <48rm4e$1eb@engnews1.eng.sun.com>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!taumet!clamage
References: <48m6b8$2ll@engnews1.eng.sun.com> <DID3FH.12F@falcon.daytonoh.attgis.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: 21 Nov 1995 15:58:46 GMT
Organization: Sun Microsystems Inc., Mountain View, CA
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <48rm4e$1eb@engnews1.eng.sun.com>
References: <48m6b8$2ll@engnews1.eng.sun.com> <DID3FH.12F@falcon.daytonoh.attgis.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: 1915
X-Lines: 50
Originator: clamage@taumet