|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Throws an exception within a procedure.
- Required. Provides information about the exception to be thrown.
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.
The following code uses the Throw statement to throw an exception:
' Throws a new exception. Throw New System.Exception("An exception has occurred.")
Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)