Re:You’re better off using Exceptions
by waynecochran on Monday February 03, 2020 @01:43PM
(#22227426)
Yes... RAII is handy, but it doesn’t save you from checking EOF logic in my example.
[ Parent
| on HN ]
Re:You’re better off using Exceptions
by safety-second on Monday February 03, 2020 @02:41PM
(#22228106)
You 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.
Re:You’re better off using Exceptions
by quietbritishjim on Monday February 03, 2020 @05:49PM
(#22230231)
Exceptions 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.