-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Completion of error handling #533
Comments
Interesting. What would you do for these specific cases? |
Not sure about the others, but for the first one using |
What about using a std::unique_ptr with custom deleter for the FILE in ImageLoader? |
Are you interested to apply aspect-oriented software development? |
I don't think so. First, everything has been loaded successfully so I don't see why we would return a failure. Secondly, it doesn't solve the real problem that your file failed to close properly (and thus is still open).
How would that handle the error code returned by fclose?
I'm not going to change error handling in SFML right now. But I'm open to ideas for SFML 3. |
This is about writing, not loading? (At least in this instance. For code that's loading, I'd say the return value is not as important.)
That's true, but again not really sure how to solve this properly for all cases. |
Oops 😄
That's my point. Sometimes there's no way to properly handle an error case, and the best solution is to do nothing. The error that is likely to occur with fclose, is a failure to flush the last chunk of buffered data because the disk is running out of space. In this case what should we do? Report failure and try to revert all our changes? If the file was newly created, we must remove it and possibly have to handle other file system errors... this is an endless task. If the file was already existing and was overwritten by the function, reverting is impossible. So we should definitely do nothing, now the question is: should we report failure or success? I'd say that we should report a failure in this case. By the way, funny reading: https://groups.google.com/forum/#!msg/comp.lang.c/bc46Pp8wiM4/alPdYP3DAcYJ |
That's really a problem with no 100% satisfying solution. C++ streams close the file in the destructor and thus have no option of reporting failure. In Java, the developers tried to fix this problem by requiring checked exceptions, which didn't quite go the way they intended -- it became almost a common idiom to write empty try-catch clauses around I agree that it would be good to at least report the error, because a user getting One problem of the current API is also that there's no way to know what kind of error happened, so the user is lost if the call fails. |
Using exceptions in SFML 3 should solve this problem. |
This specific one yes, but exceptions can't be applied everywhere. For example, classes that keep a file handle open and close it in their destructor (such as |
Throwing an exception from a destructor is only an issue when there is already an unhandled exception so the stack is unwinding, in which case std::terminate is called. |
Are you suggesting we should throw exceptions nevertheless? Or use No, no, never let exceptions leave destructors, it will only wreak havoc. See also GotW 47. |
At the very least we should have a |
Is it realistic to consider a failure when closing a file in read-only access? And even if it happened, the app would still behave as expected (I'm still talking of |
Le 19/02/2014 15:35, Peter Atashian a écrit :
|
What about postponing this to SFML 3? |
If something can be done right now we should do it, so that when we switch to exceptions in SFML 3, the code to modify will already be clearly identified. But if the solution is not so obvious, yes, let's forget about it for now. |
Some of them can be solved in SFML 2.x without exceptions. For example, if Mutex and key (for thread-local storage) construction fails if there are not enough system resources, and destruction fails if a lock is still held. The standard As mentioned earlier, it's a bad idea to throw exceptions from destructors. But if SFML 3 uses C++11, the classes |
So... is this issue still scheduled for fixing before SFML 3? If a more or less complete list can be provided of sites where error codes aren't checked, I can probably come up with a fix for this. |
I'd say we should fix it before SFML 3. The question is, If there are more of these code pieces that don't generate an error up on failing. |
So... to create a sort of agenda for this issue... What needs to be done:
|
I have looked at a few source files for your current software. I have noticed that some checks for return codes are missing.
Would you like to add more error handling for return values from functions like the following?
The text was updated successfully, but these errors were encountered: