Talk:C++ Programming/RAII

I love this article! Thanks! Ollydbg (talk) 11:04, 29 December 2008 (UTC)

I must object to the content on this page. A large part of the difference between the two examples is that the class in the RAII version throws exceptions thus making error detection easier. This is of course very nice, but a separate issue then RAII. Contributions/70.70.53.2 (talk) 22:59, 15 June 2009 (UTC)


 * Let's say the non-RAII version was changed to the following initialization:


 * In this case, the class would throw an exception; the non-RAII function would still have to catch the error (possibly the std::bad_alloc as well) and manually free this object before rethrowing the exception. As such, error checking would still be necessary even if you modify the function to use the custom class; at best, simply remove the if statement surrounding individual write statements.  --Sigma 7 (talk) 03:14, 16 June 2009 (UTC)

Real problem that statement Furthermore, file instances guarantee that a valid log file is available (by throwing an exception if the file could not be opened). is a lie, because mostly you dial with buffered files, and write error will be detected on close, which happens to be in destructor and so error is ignored, i.e. you will get damaged log file: The fclose function may also fail and set errno for any of the errors specified for the routines close, write, or fflush.