🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: object contruction/destruction in c++, design flaw?

#2195
From: Fergus Henderson
Date: Sat, 14 Oct 1995 08:02
36 lines
1742 bytes
"James M. Curran" <72261.655@CompuServe.COM> writes:

>|>    a::a()
>|>    {
>|>        mBuffer1 = new char[ 1000 ] ;
>|>        try
>|>        {
>|>            mBuffer2 = new char[ 1000 ] ;
>|>        }
>|>        catch (...)
>|>        {
>|>            delete mBuffer2 ;
>|>        }
>|>    }
>
>That last bit should be "delete mBuffer1;", shouldn't it?  

Closer, but still not quite right.  It should use the array delete
syntax, and after deleting mBuffer1, it should rethrow the exception:

        catch (...)
        {
            delete [] mBuffer1;
	    throw;
        }

-- 
Fergus Henderson             |  "Australia is the richest country in the world,

fjh@cs.mu.oz.au              |   according to a new system of measuring wealth
http://www.cs.mu.oz.au/~fjh  |   announced by the World Bank yesterday."
PGP: finger fjh@128.250.37.3 |  - Melbourne newspaper "The Age", 18 Sept 1995.
---
[ 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: <9510140557.6541@mulga.cs.mu.OZ.AU>
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <44odn6$c61@gabi.gabi-soft.fr> <45jmri$cj6$1@mhafm.production.compuserve.com>

Show Full Headers
Complete Article Headers
Approved: fjh@cs.mu.oz.au
Date: 14 Oct 95 08:02:55 GMT
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Message-ID: <9510140557.6541@mulga.cs.mu.OZ.AU>
Newsgroups: comp.std.c++
Organization: Computer Science, University of Melbourne, Australia
Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back
References: <44odn6$c61@gabi.gabi-soft.fr> <45jmri$cj6$1@mhafm.production.compuserve.com>
Subject: Re: object contruction/destruction in c++, design flaw?
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBFAgUBMH9u0OEDnX0m9pzZAQGMrAF/fduvBut17gFuthFxJ4Q8G8QCPGPXX08I
 ADUORJRt3PJYREGfI8+R98ScHlVVGXnI
 =I9Zp