home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,537 of 33,346   
   Dave Harris to Henry   
   Re: Exception in Constructor   
   16 Sep 12 21:16:54   
   
   From: brangdon@cix.compulink.co.uk   
      
   hc128168@googlemail.com (Henry) wrote (abridged):   
   > Inside A::A(), I new-ed B and then threw an exception on purpose,   
   > and obviously, A::~A() and B::~B() weren't called.   
   > It doesn't seems to me that "if a constructor finishes by throwing   
   > an exception, the memory associated with the object itself is   
   > cleaned up - there is no memory leak" is true.   
      
   By "the object itself" it means A; that is, the object whose's   
   constructor threw. And "cleaned up" just means the memory is freed,   
   not that destructors are executed.   
      
   If you move the throw to B's constructor, B's destructor still won't   
   be called, but B's (and A's) memory will be freed.   
      
   To observe this, you'd need to hook into operator new() at some level.   
      
   -- Dave Harris, Nottingham, UK.   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca