Relative Content

Tag Archive for c++fileraii

Is it smart to use RAII to manage files?

I wanted to create a class Channel that facilitates file writes in a special way. It was clear to me at first that I call open() on the file in the constructor and close() on the file descriptor in the destructor. But this would mean that I have to throw in the destructor if close() fails for some reason. Is it smart to use RAII for file management anyway? Should I throw in the destructor?