Thread View: comp.std.c++
2 messages
2 total messages
Started by Ramon Pantin
Fri, 21 Aug 1992 03:00
constructors and exceptions
Author: Ramon Pantin
Date: Fri, 21 Aug 1992 03:00
Date: Fri, 21 Aug 1992 03:00
16 lines
1079 bytes
1079 bytes
Could one of the ANSI-C++ folks that have "paper experience" :-) with how exception handling is supposed to work give a summary of how will an exception thrown from a constructor interact with objects previously constructed in the same "try" block. Also would you please illuminate us on how an exception thrown from the constructor of a derived object (which executes after the construction of the base object) interacts with the destruction of the base object. Will the destructor for the base object be called when the exception is thrown? What about an exception thrown from a signal handler (yuck!) that interrupted the construction of an object? Ramon Pantin
Re: constructors and exceptions
Author: Mark Mendell
Date: Fri, 21 Aug 1992 03:25
Date: Fri, 21 Aug 1992 03:25
40 lines
2161 bytes
2161 bytes
Real working exception handling in the IBM xlC C++ compiler on the RS/6000: In article <2286@devnull.mpd.tandem.com> you write: > >Could one of the ANSI-C++ folks that have "paper experience" :-) >with how exception handling is supposed to work give a summary of how >will an exception thrown from a constructor interact with objects >previously constructed in the same "try" block. An exception in a constructor will destroy the object being constructed (as far as it has been constructed), then destroy all previously constructed objects in the try block, and then try matching the catch clauses. This will repeat up the static and dynamic blocks until a catch block is found that matches the exception, or else terminate() will be called. > >Also would you please illuminate us on how an exception thrown from >the constructor of a derived object (which executes after the construction >of the base object) interacts with the destruction of the base object. >Will the destructor for the base object be called when the exception >is thrown? Any part of the object that has been created will be destroyed (in reverse order). In particular the base destructor will be called, but not the derived destructor, because the derived object isn't completely contructed yet. > >What about an exception thrown from a signal handler (yuck!) that >interrupted the construction of an object? Under xlC, you are not allowed to do a throw from a signal handler. This restriction is due to the implementation of exception handling. Different implementations might allow you to do this. On the other hand, the only portable action allowed by ANSI C in a signal handler is to set a variable of type sigatomic_t. -- Mark Mendell IBM Toronto Lab mendell@torolab6.vnet.ibm.com
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads