首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

怎么捕捉方法中的错误

2012-02-15 
如何捕捉方法中的异常一个方法要返回一个int值我现在想在方法内实现捕捉异常应该怎么处理?[解决办法]int r

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

热点排行