🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Exceptions and Destructors

#3466
From: David Byrden
Date: Fri, 16 Feb 1996 03:57
46 lines
2430 bytes
>>> struct foo : public other
>>> {
>>>     ~foo {throw("BAD?");}
>>> };

>> Since the above does not result in an infinite loop on the compilers I
>> have access to, I presume that the object is considered destructed
>> when the dtor is entered.


  Compilers do not serve as a reliable definition of anything. The draft 
C++ standard is available at  http://www.cygnus.com/misc/wp/jan96  and 
a query of it is less painful than a debugging session.   :)

A quote:

15.3.10
The  fully  constructed base classes and members of an object shall be
destroyed before entering the handler of a function-try-block  of  a
constructor or destructor for that object.


  I cannot easily find any other mention of when sub-objects are 
destroyed during a destructor throw. I presume that somewhere it states 
that they shall be destroyed, since you could always force their 
destruction by writing a function-try-block with an empty handler.

  I assume that you expected your infinite loop when a *stack* object is 
destroyed, since the block in question then becomes subject to stack 
unwinding. In fact, the object which threw is excluded from the 
unwinding. This makes sense when you consider the situation of a block 
that declares multiple local objects, and destroys them in reverse order. 
If one of them throws, destruction of the whole lot does not start over 
again.


  It is generally not advisable to write destructors that throw. This can 
lead to termination of the program when they do so during stack 
unwinding, or when their object is a global.


                               David
---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  Moderation policy:
  http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
Technical Details
Message-ID: <4g0civ$dq5@news.bridge.net>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <BGLENDEN.96Feb14173755@colobus.aoc.nrao.edu>

Show Full Headers
Complete Article Headers
From: David Byrden <100101.2547@compuserve.com>
Message-ID: <4g0civ$dq5@news.bridge.net>
X-Original-Date: 15 Feb 1996 22:37:19 GMT
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
Date: 16 Feb 96 03:57:55 GMT
Approved: fjh@cs.mu.oz.au
Newsgroups: comp.std.c++
Subject: Re: Exceptions and Destructors
Organization: self-employed
References: <BGLENDEN.96Feb14173755@colobus.aoc.nrao.edu>
X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMSQA3uEDnX0m9pzZAQHzmQF9Fs/RJ9HRAog0ms+1Nm3Zb91eNmh7rwUW
 yTJTS9MT8HpaeOFhFN4Oh+L8RELZSPR5
 =6YYZ