Skip to Content
VB.NET Language in a Nutshell, Second Edition
book

VB.NET Language in a Nutshell, Second Edition

by Steven Roman PhD, Ron Petrusha, Paul Lomax
April 2002
Intermediate to advanced
688 pages
19h 51m
English
O'Reilly Media, Inc.
Content preview from VB.NET Language in a Nutshell, Second Edition

Name

Throw Statement

Syntax

Throw exception
exception (required; an Exception object or an object derived from Exception)

An Exception object representing the exception being thrown

Description

Throws an exception that can be handled using either structured exception handling (a Try . . . Catch block) or unstructured exception handling (the On Error statement)

Example

Try
    ' Ask for a positive number
    Dim DataCt As Integer = CInt(InputBox("Enter number of items."))
    ' Check for error
    If DataCt <= 0 Then
        ' Throw an exception
        Throw New Exception("Must enter a positive number.")
    End If
Catch ex As Exception
    MsgBox(ex.Message)
End Try

VB.NET/VB 6 Differences

The Throw statement is new to VB.NET.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

VB .NET Language in a Nutshell

VB .NET Language in a Nutshell

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596003080Supplemental ContentCatalog PageErrata