I have a basic try..except
to catch errors when trying to load a PNG file into a TImage
:
try
Previewimage.Picture.LoadFromFile(filename);
except
//code to handle exception
end;
Normally this works fine if the file does not exist, or in my case the PNG is corrupted. I have no control over the source creation of the PNG, so need to catch when the PNG cannot be loaded, ie it gives the error:
This "Portable Network Graphics" image is not valid because it contains invalid pieces of data (crc error).
My issue is that the try..except
is within a worker thread. This seems to cause the try..except
to be ignored, and my program crashes with the CRC exception.
Are there any easy fixes for this issue?