什么是diff bw throw ex;投掷; [英] what is diff bw throw ex; and throw;

查看:87
本文介绍了什么是diff bw throw ex;投掷;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





什么是差异b /



catch(Exception ex)

{

抛出ex;

}







catch(例外情况)

{

throw;

}



谢谢

Hi,

What is the diff bw

catch(Exception ex)
{
throw ex;
}

and

catch(Exception ex)
{
throw;
}

Thanks

推荐答案

浏览此链接

http://stackoverflow.com/questions/730250/is-there-a-difference-between-throw-and- throw-ex [ ^ ]

希望这有助于
Go through this link
http://stackoverflow.com/questions/730250/is-there-a-difference-between-throw-and-throw-ex[^]
Hope this helps


catch(Exception ex)
{
throw;
}





这意味着从被调用的地方抛出异常。例如假设你有函数xyz( )并且在这个xyz()中你写throw; ,现在你在Main()函数中调用xyz()函数,如果有异常则xyz()函数会将异常抛出到main函数。



但是如果你这样写的话





It means the exception is thrown to fuction from where it is called .for example suppose you have function xyz() and in this xyz() you write "throw;" ,now u are calling xyz() function in Main() function, if there is exception then xyz() function will throw the exception to the main function.

but if you write like this

catch(Exception ex)
{
throw ex;
}





那么它会终止你的程序。如果我们谈论上面的场景,那么异常会抛到主函数由XYZ()。



then it will terminate you program.If we talk about the above scenario then the exception will thrown to the main function by XYZ().


这篇关于什么是diff bw throw ex;投掷;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆