一个方法要返回一个int值
我现在想在方法内实现捕捉异常
应该怎么处理?
------解决方法--------------------------------------------------------
int returnValue = -1;
try
{
//todo..
returnValue = 1;
}
catch
{
returnValue = 0;
}
return returnValue;
------解决方法--------------------------------------------------------
for example:
private int Test(int a,int b)
{
try
{
//操作
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}
//调用
try
{
Test(1,2);
}
catch(Exception ex)
{
//异常处理..
}