4 ms·
Yes... RAII is handy, but it doesn’t save you from checking EOF logic in my example.
by waynecochran 7y ago
Yes... RAII is handy, but it doesn’t save you from checking EOF logic in my example.
- safety-second 7y agoYou could use a File class that throws on EOF, but that would be a really bad idea for C++ since throw/catch are very expensive.
- quietbritishjim 7y agoExceptions are expensive compared to a simple function call, but I imagine they're cheap compared to operations that read from disk. Certainly one exception per file close is not going to hurt.