Visual Basic Language Reference  

Throw Statement

Creates an exception within a procedure.

Throw expression 

Part

expression
Required. Provides information about the exception to be thrown.

Remarks

The Throw statement creates 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.

Example

The following code uses the Throw statement to create an exception:

' Throws a new exception.
Throw New System.Exception("An exception has occurred.")

See Also

Try...Catch...Finally Statements | On Error Statement | Structured Exception Handling | Unstructured Exception Handling