我在课堂上有以下方法ProductServices
:
public bool IsDownloadAllowed(int Id, string productId)
{
if (CustomStringFunctions.IsGuid(productId))
{
//Do Something
}
else
{
throw new FormatException("The Guid must be a valid Guid!");
}
}
如果我使用以下说明中的方法:
var _productServices = new ProductServices();
try
{
var flag = _productServices.IsDownloadAllowed(Id, productId);
//do something
}
catch (Exception e)
{
//handle exception
}
该catch
语句未捕获异常。我也尝试用没有运气的方式Exception
替换FormatException
。我究竟做错了什么?