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 33,181 of 33,346   
   Richard Phillips to All   
   RAII advice (for a RAII newbie)   
   30 Aug 13 12:28:52   
   
   From: riph72@googlemail.com   
      
   { Reformatted; please limit your lines to 70 chars -mod }   
      
   Hello all,   
      
   Going forward, I'm keen to start using RAII on projects, but in order   
   to justify my future evangelism, I want to clarify a few things...   
      
   So, borrowing an example from Jon Kalb's excellent tutorial videos:   
      
   // BAD   
   {   
   	dosomething();   
   	cleanup();   
   }   
      
      
   // GOOD (RAII)   
   {   
   	CleanupType cleanup;   
   	dosomething();   
   }   
      
      
   // ????   
   {   
   	try   
   	{   
   		dosomething();   
   		cleanup();   
   	}   
   	catch (const std::exception& ex)   
   	{   
   		cleanup();   
   	}   
   	catch (...)   
   	{   
   		cleanup();   
   	}   
   }   
      
   Why is the 2nd (RAII) approach superior to the third approach?  I   
   presume there's more to it than "appearance"?  While the third   
   approach looks more complicated, it doesn't have to worry about a   
   "CleanupType"...   
      
   Regards,   
   Richard.   
      
      
   --   
         [ 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