Permalink
Fetching contributors…
Cannot retrieve contributors at this time
81 lines (65 sloc) 2.67 KB
title ms.date ms.prod ms.reviewer ms.suite ms.technology ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author translation.priority.ht
Throw Statement (Visual Basic)
2015-07-20
.net
devlang-visual-basic
article
vb.Throw
VB
structured exception handling, throw statements
try-catch exception handling, throw statements
throw statement, about throw statements
throwing exceptions, throw statement
exception handling, throw statement
On Error statement, throwing exceptions
throwing exceptions
exception handling, unstructured
throw statement
a6e07406-5c8a-4498-87a2-8339f3651d62
15
dotnet-bot
dotnetcontent
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

Throw Statement (Visual Basic)

Throws an exception within a procedure.

Syntax

Throw [ expression ]  

Part

expression
Provides information about the exception to be thrown. Optional when residing in a Catch statement, otherwise required.

Remarks

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.

A Throw statement with no expression can only be used in a Catch statement, in which case the statement rethrows the exception currently being handled by the Catch statement.

The Throw statement resets the call stack for the expression exception. If expression is not provided, the call stack is left unchanged. You can access the call stack for the exception through the xref:System.Exception.StackTrace%2A property.

Example

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

[!code-vbVbVbalrStatements#84]

Requirements

Namespace: Microsoft.VisualBasic

Module: Interaction

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

See Also

Try...Catch...Finally Statement
On Error Statement