Throw Statement


Throw Statement

Syntax

     Throw exception 


exception (required; Exception or derived from Exception)

A System.Exception object representing the exception being thrown

Description

The Throw statement initiates an exception that can be handled using either structured exception handling (with a TRy...Catch...Finally statement) or unstructured error handling (with an On Error statement).

Example

     Dim positiveNumber As Integer     Try        ' ----- Throw an exception if the user enters anything other        '       than a positive number.        positiveNumber = CInt(InputBox("Enter number of items."))        If (positiveNumber <= 0) Then           Throw New Exception("Entry must be a positive number.")        End If     Catch ex As Exception        MsgBox(ex.Message)     End Try 

Version Differences

The Throw statement is new to VB under .NET.

See Also

Exception Class, Try...Catch...Finally Statement




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net