Exclusion guarantees are not documented, so you cannot accept anything.
Looking at the source code for CImage::Load
(atlimage.h), it is found that the inability to download the image can destroy the previously saved image. Both shipments Load
ultimately cause CImage::CreateFromGdiplusBitmap
. This member of the class performs two operations: 1.) It calls Create
to create a new storage for the image. This operation is destructive. 2.) It copies the original image data to the destination. This operation may fail.
Since you have an operation that may fail after an operation that destroys any previous data, you cannot assume that a failure to load the image will save the previous image data.
The following code implements the loading of a non-destructive image, first loading the image in a temporary place and assigning it to the destination only with success:
HRESULT NonDestructiveLoad( CImage& img, const CString& fileName ) {
CImage tempImage;
HRESULT hr = tempImage.Load( fileName );
if ( SUCCEEDED( hr ) ) {
img.Destroy();
img.Attach( tempImage.Detach() );
}
return hr;
}