Re:Problems with C++ exceptions
by gblargg on Wednesday November 12, 2025 @01:34AM
(#45897002)
Agreed. Author is trying to mix paradigms. Simplest approach if they want local handling and non-propagation of errors is to just have the file holder not check for open success, and check that manually after construction. Then you get guaranteed closure of file no matter how the function is exited.
[ Parent
| on HN ]
Re:Problems with C++ exceptions
by actionfromafar on Wednesday November 12, 2025 @03:58AM
(#45897910)
Goes against "Resource acquisition is initialization" though to have objects which exist but can't be used. (I think that's the relevant pattern?)
However, where the language and it's objects and memory ends and the external world begins, like files and sockets... that's always tricky.
this may lose the value of errno, right?
Yes, it would. It would be trivial to add errno as an instance variable for File_Handle class though.