96e9e392   
   From: dave@boostpro.com   
      
   on Wed Nov 09 2011, "A. McKenney" wrote:   
      
   > On Nov 7, 2:57 pm, Ulrich Eckhardt    
   > wrote:   
   >> Am 06.11.2011 09:45, schrieb A. McKenney:   
   >>   
   > ...   
   >> > I would argue the opposite.   
   >   
   >>   
   >> > It is much harder to write code that does _not_ leak resources if   
   >> > you have to worry about exceptions. Nobody had to worry about   
   >> > exception safety before exceptions were introduced.   
   >>   
   >> If you use the spirit behind RAII consequently, you can return from any   
   >> line of code just as you can throw from any line of code and no   
   >> resources are leaked. It's just that you need to put the resource   
   >> management in the hands (read: constructor and destructor) of types that   
   >> explicitly guarantee the according policy.   
   >   
   > This is called "exception safety",   
      
   No, this is called "correct error handling," and it applies whether   
   you're using exceptions or error codes or something else.   
      
   > and I'm not the only one who considers it an advanced C++ topic --   
   > a large chunk of Herb Sutter's _Exceptionsl_C++_ is devoted to   
   > exceptions and exception safety.   
      
      
      
   > It gets a _lot_ harder when you throw in multiple threads   
      
   Not a lot. Threads may not exit via an exception, and it's simple to   
   avoid creating such threads. What's a bit trickier, until you have   
   C++11, is storing the exception and rethrowing it in the calling thread.   
      
   > (virtually all the code I work on is multi-threaded); at a certain   
   > point, RAII seems like just a garnish on the real work of avoiding   
   > resource leaks and deadlocks. I suspect there are other   
   > situations which are similar.   
   >   
   > And it only works if _everyone_ does it right.   
      
   Yes, just like your program only works if all the code is right.   
      
   > Specifically, every resource that is handled in any of the levels   
   > between throw and catch has to be exception-safe. I also suspect   
   > that there are multiple incompatible interpretations of "doing it   
   > right," too, though I can't say that I've had the experience of   
   > dealing with a co-worker's idea of exception safety.   
      
   Exception-safety is simply defined, and there's only one correct   
   definition: when an exception is thrown, all invariants are preserved   
   (and no resources are leaked, which can be declared to be part of the   
   invariant). But that's not a special rule for exceptions; that's the   
   rule for correct programs in general.   
      
   --   
   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)   
|