TITLE: exceptions and intializer lists SM = Scott Meyers (smeyers@netcom.com, author of "Effective C++") JS = John Skaller (maxtal@Physics.usyd.edu.au), 28 May 95 SM: 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, JS: Correct. The purpose is to permit TRANSLATION of the exception. NOT cleanup. SM: 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 } JS: NO. The purpose is to TRANSLATE the exception like this: try { .. } catch(...) { throw "Address Book Entry Torn"; } SM: I know I can solve this problem by making address_ and phones_ auto_ptr objects, JS: Yes. OR you can put the "new" inside the constructor body. SM: but now I'm wondering: how *are* you supposed to use function try blocks? They don't seem to help in this case. JS: 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).