It is important to detect an error when closing the file that you wrote to, because the last part of your data could be cleared during closing, and if it is lost, your last record was effectively unsuccessful, and someone should know about it, Destructor for A file object is a great place to close automatically, but people say they don’t throw exceptions from destructors, so if closing fails, then how do you know about it?
I heard that people recommend manually accessing the close () method. This sounds good, except what happens if the close () methods for multiple files do not work in this situation:
MyFile x(0), y(1), z(2);
x.close();
y.close();
z.close();
?
Well, it looks like if the close () method for "x" throws an exception, you did your best to defend the rule to avoid throwing exceptions in the "x" destructor, except that you intentionally made early calls to the close () "y" methods and "z" will not be executed until their destructors. So, then, when the close () method "y" is called in the destructor "y" or the close () method "z" is called in the destructor "z", and if they make exceptions, then you are "screwed".
Is there any reasonable way not to get into such a situation?
Steel source
share