Is there a reason Image.FromFile throws an OutOfMemoryException for an invalid image format?
Posted
by Arc
on Stack Overflow
See other posts from Stack Overflow
or by Arc
Published on 2010-04-09T19:44:31Z
Indexed on
2010/04/09
19:53 UTC
Read the original article
Hit count: 372
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?
© Stack Overflow or respective owner