From: bouncer@dev.null   
      
   Zeljko Vrba wrote:   
      
   > On 2012-06-14, Wil Evers wrote:   
   >>   
   >> And here's mine, slightly edited too. It just calls yours:   
   >>   
   >> void save()   
   >> {   
   >> outfile f(/* ctor args */);   
   >> write_contents(f);   
   >> f.close();   
   >> }   
   >>   
   >> Do we really need a language change for this? I rest my case.   
   >>   
   > Of course not, but do we need RAII at allthen ? And why is RAII   
   > then so often cited as one of main advantages of C++ when it is   
   > so easily emulated?   
      
   There is RAII in this example: we rely on the guarantee that f's   
   destructor is called, even if an exception is thrown from the call to   
   write_contents(f).   
      
   In that case, the stack unwinding machinery takes control, so f.close()   
   is *not* called, and that is deliberate. It implies that f.close()   
   is free to throw an exception if it detects a problem, without risking a   
   call to terminate().   
      
   As I tried to explain before, even if f.close() is not called, there is   
   no resource leak, because the f's destructor simply releases any   
   resources that haven't been released before. However, it will never   
   throw.   
      
   Regards,   
      
   - Wil   
      
      
   --   
    [ 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)   
|