ArgumentOutOfRangeException is thrown when the value of an argument is outside the allowable range
Imports System
Module Module1
Public Sub Main()
Try
Dim guest1 As Guest = New Guest("A", "B", 17)
Catch outOfRange As Exception
Console.WriteLine("Error: {0}", outOfRange.Message)
End Try
End Sub
Class Guest
Public Sub New(ByVal fName As String, ByVal lName As String, ByVal age As Integer)
If (age < 21) Then
Throw New ArgumentOutOfRangeException("age", "All guests must be 21-years-old or older.")
End If
End Sub
End Class
End Module
Related examples in the same category