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

如何捕捉方法中的异常

2014-01-28 
一个方法要返回一个int值 我现在想在方法内实现捕捉异常 应该怎么处理?------解决方法--------------------

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

        

热点排行