At the end of the day this is a further incarnation of the famous question: "ARE EXCEPTIONS EVIL?"I believe you are asking two questions in one. It's a great questionShould you use exceptions or return values? Should you use RAII or not?
If exceptions are not permitted in your company, then fstream::exceptions() must be set globally for a flame waryour project. And you have to interrogate the error flag too.
If RAII is not permitted in your company, then do not use C++. If you use RAII, then any exception thrown in the destructor will be swallowed. This sounds terrible and it is. However I agree with others that RAII is the way to go also because any error handling here is futile and creates unreadable code. This is because "flush" does not do what you may think it does. It instructs the operating system to do it on your behalf. The explicit closeOS will do it when it believes it is convenient. Then, when the operating flushes (which may be a good idea if exceptions are deprecated byminute after your teamfunction returns) similar things may happen at the hardware level. The style anddisk may have an SSD cache which it flushes to the return value of you function actually suggests that thisrotating disks later (which may behappen at night when it is less busy). At last the casedata ends on the disk.
But if exceptions are deprecated youthe story does not end here. The data may have to interrogatebeen saved correctly but the error flags after writing and after closing and return true or false accordinglydisk gets destroyed by whichever of the many possible causes. Just closing explicitlyHence if RAII is not transactionally safe enough by far.
fstream::exceptions() will tellfor you more or, then you set itneed to what you wantgo to a lower API level anyway and even that will not be perfect. Sorry for being a party pooper here.