qadeer37
Well-known member
VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim obj As New Minimal
Dim userAge As Integer
userAge = CType(InputBox("Please enter your age"), Integer)
MessageBox.Show(obj.Age.ToString)
End Sub
Public Class Minimal
Private m_Age As Integer
Property Age() As Integer
Get
Age = m_Age
End Get
Set(ByVal value As Integer)
If value < 0 Or value >= 100 Then
Dim AgeException As New ArgumentException("Age must be within 0 to 100")
Throw AgeException
Else
m_Age = value
End If
End Set
End Property
End Class
Even if the user enter age more then 100 program doesn't halts. What I want to do is that if user enter an age above 100 an exception should be shown so that user is informed and without try catch. I think there must be some code in minimal class to do so.