VB.NET中的错误处理 [英] Error Handling in VB.NET
本文介绍了VB.NET中的错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我在VB.net中遇到有关错误处理"的问题
抛出异常"和抛出新异常"是什么意思?
以及何时应该使用它?
我了解使用Try ... Catch ... Finally
但是我不知道使用投掷"吗?
请帮忙.
Hi everybody
I got a question about "Error Handling" in VB.net
what''s the meaning of "Throw Exception" and "Throw new Exception"?
and When we should use it?
I understand the using of Try...Catch...Finally
But I don''t know the using of "Throw"?
Please help..
推荐答案
Throw可让您在应用程序中引发自己的异常,然后可以使用try..catch捕获异常.您还可以重新引发捕获的异常:
Throw lets you raise your own exceptions within your application which can then be caught with try..catch. You can also re-throw caught exceptions:
try
{
myBuggyCode.myFlakyMethod("some parameter bla bla");
}
catch(Exception ex)
{
logger.Error(ex);
throw ex;
}
在jim的答案上稍作扩展.
throw
用于显示已经引发的异常,并且经常被捕获在catch块中.
throw new ....
通常用于以下情况:
To expand a little on jim''s answer.
throw
is used to surface an Exception that has already been raised, and often caught in a catch block.
throw new ....
is often used in circumstances like:
if (divisor == 0)
{
throw new DivideByZeroException("Naughty, naughty");
}
这篇关于VB.NET中的错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文