Wrong by Default
I can’t believe that people still use opening&#x2F;closing files as examples of RAII when that is one of the cases that RAII <i>can’t</i> handle correctly. A call to close is the last chance the operating system has to signal that an error occurred when writing. You can’t easily signal errors in destructors. In C++, you basically can’t throw an exception and there is no return value from a destructor. Rust suffers the same kind of problem. The only way to properly close a file is to use regular old explicit control flow with if statements. Then you can handle the errors in the normal way.