SyntaxThrow exception
DescriptionThe 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). ExampleDim 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 DifferencesThe Throw statement is new to VB under .NET. See AlsoException Class, Try...Catch...Finally Statement |