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,415 of 33,346   
   Dave Abrahams to All   
   Re: Will we ever be able to throw from a   
   17 Jun 12 13:24:43   
   
   From: dave@boostpro.com   
      
   on Fri Jun 15 2012, DeMarcus  wrote:   
      
   > I have always had the feeling that throwing from   
   > a destructor is a bad idea, but I've never seen a proof that it will   
   > be impossible even with future C++. Therefore I tried to state such   
   > "proof".   
   >   
   > With the input from the people here I managed to come up with an even   
   > better "proof" (at least in regards to convince myself). It's the   
   > following.   
      
   I don't understand the drive to convince yourself that the idea of   
   throwing from destructors is somehow fundamentally broken.   
      
   > We can't throw from destructors unless we are able to bulk up all   
   > exceptions thrown from all the destructors until the first catch.   
      
   Either that, or throw out information from secondary exceptions.   
      
   > Even if that was possible we would need to choose between   
   >   
   > 1. Just running each destructor until it throws and then proceed with   
   > the next destructor.   
   >   
   > 2. Running the whole destructor even if it throws (bulking it).   
      
   I don't unknw what either of these things mean.  C++ already has   
   well-defined semantics for what happens when a dtor throws, but not during   
   stack unwinding.  It's easy to extend these semantics for exceptions   
   thrown during unwinding if you're willing to chain up multiple   
   exceptions or throw out secondary exception information.   
      
   > In 1. we would likely have resource leaks. In 2. we would likely have   
   > undetermined behavior.   
      
   These conclusions seem flimsy at best and completely unsupported at   
   worst.  If you code to account for the semantics of exceptions thrown   
   from destructors, you can throw them.  If you don't code to account for   
   those semantics, throwing from a destructor is likely to do something   
   undesirable.  This is exactly the same as the way the use of any other   
   feature (e.g. placement new) works if you account for its semantics, and   
   will get you in trouble if you code as though it hadn't happened.   
      
   --   
   Dave Abrahams   
   BoostPro Computing   
   http://www.boostpro.com   
      
      
         [ 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