Throw Statement |
Throw exception
An Exception object representing the exception being thrown
Throws an exception that can be handled using either structured exception handling (a Try . . . Catch block) or unstructured exception handling (the On Error statement)
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
The Throw statement is new to VB.NET.
Exception Class, Try...Catch...Finally Statement