Close file handle if exception occurs in image class

ref #10392 

cc @georgehrke @DeepDiver1975 @icewind1991 @th3fallen