I recently updated some code used to take screenshots using the WinAPI feature set in GetWindowDC β CreateCompatibleDC β CreateCompatibleBitmap β SelectObject β BitBlt β GetDIBits. Now I check all these errors because they can and sometimes fail. But then I have to clean up by deleting the created bitmap, deleting the created dc and letting go of the dc window. In any example that I saw - even on MSDN - related functions (DeleteObject, DeleteDC <ReleaseDC) are not checked for failure, apparently because if they were received / created by OK, they will always be deleted / released by OK. But they can still fail.
This is just one noteworthy example, since the challenges are next to each other. But sometimes there are other functions that can fail, but in practice they never do. For example, GetCursorPos. Or functions that may fail only if invalid data is transferred, such as FileTimeToSytemTime.
So, is it good to check ALL functions that may fail to fail? Or is there anything in order not to check? And as a result, when checking these functions "never-unsuccessfully" for failure, what is right? Throw an exception at runtime using assert, something else?
rotanimod
source share