如何在 VB.NET 中引发异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13151322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to raise an exception in VB.NET
提问by CJ7
How should an exception be raised in VB.NET?
如何在 VB.NET 中引发异常?
回答by Adriaan Stander
You would throw a new exception.
你会抛出一个新的异常。
Have a look at Throw Statement (Visual Basic)
The Throw statement throws an exception that you can handle with structured exception-handling code (Try...Catch...Finally) or unstructured exception-handling code (On Error GoTo). You can use the Throw statement to trap errors within your code because Visual Basic moves up the call stack until it finds the appropriate exception-handling code.
Throw 语句抛出一个异常,您可以使用结构化异常处理代码 (Try...Catch...Finally) 或非结构化异常处理代码 (On Error GoTo) 来处理该异常。您可以使用 Throw 语句来捕获代码中的错误,因为 Visual Basic 会向上移动调用堆栈,直到找到合适的异常处理代码。
EDIT
编辑
By request and from the link
通过请求和链接
Throw New System.Exception("An exception has occurred.")