From 3655365446645011714
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: maxtal@Physics.usyd.edu.au (John Max Skaller)
Subject: Re: Function try blocks
Date: 1995/05/28
Message-ID: <D9A6un.E1M@ucc.su.OZ.AU>#1/1
X-Deja-AN: 103755803
sender: news@ucc.su.OZ.AU
references: <smeyersD8wut1.2LK@netcom.com>
organization: School of Physics, University of Sydney, Australia
newsgroups: comp.std.c++,comp.lang.c++

In article <smeyersD8wut1.2LK@netcom.com>,
Scott Meyers <smeyers@netcom.com> wrote:
>What is the purpose of a function try block?  I thought it was to allow
>for the convenient handling of exceptions thrown in member
>initialization lists, 

	Correct. The purpose is to permit TRANSLATION of the
exception. NOT cleanup.

>  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
>  }

	NO. The purpose is to TRANSLATE the exception like this:

	try { .. }
	catch(...) { throw "Address Book Entry Torn"; }
>
>I know I can solve this problem by making address_ and phones_
>auto_ptr objects, 

	Yes. OR you can put the "new" inside the constructor body.

>but now I'm wondering:  how *are* you supposed to use
>function try blocks?  They don't seem to help in this case.

	The purpose is NOT cleanup and it is NOT for retry.
The purpose is simply to allow the exception to be caught,
analysed in the context of the object, and a more appropriate
exception object thrown.

	Cleanup MUST be coded so it works automatically.
There's no way to "intervene" in the "unwinding" process.
(Yep, objects are unwound just like the stack)

Retry MUST be handled by control transfers outside
the object being constructed -- by the subroutine that
attempted to construct the object in the first place
(or one of its parents).

--
        JOHN (MAX) SKALLER,         INTERNET:maxtal@suphys.physics.su.oz.au
	Maxtal Pty Ltd,		    
        81A Glebe Point Rd, GLEBE   Mem: SA IT/9/22,SC22/WG21 
        NSW 2037, AUSTRALIA	    Phone: 61-2-566-2189



