From mboxrd@z Thu Jan 1 00:00:00 1970 From: chip@atlantic.net To: ernst.molitor@uni-bonn.de Cc: chip@pobox.com, pkoning@xedia.com, egcs@cygnus.com Subject: Re: Exceptions in constructor? Date: Mon, 27 Oct 1997 12:10:00 -0000 Message-id: <199710272009.PAA28801@cyprus.atlantic.net> References: <199710271727.RAA00333@mibi01.meb.uni-bonn.de> X-SW-Source: 1997-10/msg01139.html According to ernst.molitor@uni-bonn.de: > :According to Paul Koning: > :> >>>>> "chip" == chip 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... A delete operator can be called without calling the destructor. That is, in fact, what the draft ANSI standard requires, when a constructor of an object created with 'new Class' throws an exception. -- Chip Salzenberg - a.k.a. - "He's Mr. Big of 'Big And Tall' fame." // MST3K