Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
waynecochran
· 6y ago · 0 comments
Yes... RAII is handy, but it doesn’t save you from checking EOF logic in my example.
Comments
[–]
safety-second
6y ago
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.
[–]
quietbritishjim
6y ago
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.