From 7503887121745143646
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 109fba,55e1f95e6a02519c
X-Google-Attributes: gid109fba,public
X-Google-Thread: f78e5,55e1f95e6a02519c
X-Google-Attributes: gidf78e5,public
From: smeyers@netcom.com (Scott Meyers)
Subject: Re: Function try blocks
Date: 1995/05/21
Message-ID: <smeyersD8xyM3.A4z@netcom.com>#1/1
X-Deja-AN: 103027291
sender: smeyers@netcom11.netcom.com
references: <smeyersD8wut1.2LK@netcom.com> <3pmpr2$nol@Mars.mcs.com>
organization: Netcom Online Communications Services (408-241-9760 login: guest)
newsgroups: comp.std.c++,comp.lang.c++

In article <3pmpr2$nol@Mars.mcs.com> mikey@MCS.COM (Mike Young) writes:
| Scott Meyers (smeyers@netcom.com) wrote:
| : However, if I try to use a function try block,
| 
| :   AddressBookEntry::AddressBookEntry(const string& name, 
| :                                      const char *address,
| :                                      const Phones *phoneNumbers)
| :   try 
| :     : name_(name), 
| :       address_(address ? new string(address) : 0),
| :       phones_(phoneNumbers ? new Phones(phoneNumbers) : 0)
| :     {}
| :   catch (...)
| :   {
| :     delete address_;       // possibly undefined
| :     delete phones_;        // possibly undefined
| :   }
| 
| address_ and phones_ are both pointers; you can safely assign them to NULL
| in ctors. The constructor body should take care of allocation. NULL

You you can't: they're const pointers in the original posting.  The only
way to give them a value is in a member init list.  And if an exception is
thrown during their initialization, you can't safely delete them.

Scott




