Is there a reason Image.FromFile throws an OutOfMemoryException for an invalid image format?
- by Arc
I am writing code that catches this OutOfMemoryException and throws a new, more intuitive exception:
/// ...
/// <exception cref="FormatException">The file does not have a valid image format.</exception>
public static Image OpenImage( string filename )
{
try
{
return Image.FromFile( filename, );
}
catch( OutOfMemoryException ex )
{
throw new FormatException( "The file does not have a valid image format.", ex );
}
}
Is this code acceptable to its user, or is OutOfMemoryException intentionally being thrown for a particular reason?