This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Exceptions in constructor?


Dear discussants, 

:According to Paul Koning:
:> >>>>> "chip" == chip  <chip@atlantic.net> writes:
:>  chip> I'm 99.44% pleased with the exception-based code I can now
:>  chip> write and test under Linux on x86.  The remaining .56% would be
:>  chip> fulfilled if throwing an exception in a constructor
:>  chip> automatically called the appropriate operator delete () if
:>  chip> there had been a call to operator new ().
:>
:> Does the C++ standard say to do that?  It would surprise me.
:
:Of course!  Without it, exceptions thrown in (or through) constructors
:would cause irreparable memory leaks.

I don't have the standard at hands, but B. Stroustrup, in his book
"C++ Programming Language" (3rd ed. paperback), states that a
destructor will be called only for objects that are "completely
constructed" (p. 367).  Depending on the source code in question, this
may mean that an exception thrown in a constructor will _not_ cause a
call of the destructor, where the call to delete would be expected (an
example is given in the book, with a note that memory leaks may be
caused by this...).

Best regards,

Ernst


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]