【发布时间】:2011-02-06 07:32:09
【问题描述】:
我正在编写代码来捕获这个OutOfMemoryException 并抛出一个新的、更直观的异常:
/// ...
/// <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 );
}
}
用户是否可以接受此代码,还是出于特定原因故意抛出 OutOfMemoryException?
【问题讨论】:
标签: c# exception exception-handling naming