问题描述
什么是差异b /
catch(Exception ex)
{
抛出ex;
}
和
catch(例外情况)
{
throw;
}
谢谢
Hi,
What is the diff bw
catch(Exception ex)
{
throw ex;
}
and
catch(Exception ex)
{
throw;
}
Thanks
推荐答案
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;投掷;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!