日期:2014-05-20  浏览次数:20981 次

如何捕捉方法中的异常
一个方法要返回一个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)
{
//异常处理..
}