Porperty checking in the Set Procedure

  • Thread starter Thread starter DotNetJunkies User
  • Start date Start date
D

DotNetJunkies User

Is there a good way to handle property checking the set procedure if the value being set does not meet the standard criteria?

Right now I just throw an error, and hope the user can handle it. Which works OK in a class, but it causes problems when I use it Custom Controls.

eg

Public Property MySeparator () As String
Get
Return mMySeparator
End Get
Set (ByVal Value As String)
If Len (mMySeparator) > 3 Then
'Is this the right way?
Throw new System.Exception ("Too long!")
Else
Me.mMySeparator = Value
End IF
End Set
 
Nothing wrong with throwing an exception. But you should use a more
appropriate exception like: System.ArgumentOutOfRangeException or
System.ArgumentException rather than the generic System.Exception. No big
deal if you don't.

DotNetJunkies User said:
Is there a good way to handle property checking the set procedure if the
value being set does not meet the standard criteria?
Right now I just throw an error, and hope the user can handle it. Which
works OK in a class, but it causes problems when I use it Custom Controls.
eg

Public Property MySeparator () As String
Get
Return mMySeparator
End Get
Set (ByVal Value As String)
If Len (mMySeparator) > 3 Then
'Is this the right way?
Throw new System.Exception ("Too long!")
Else
Me.mMySeparator = Value
End IF
End Set
engine supports Post Alerts, Ratings, and Searching.
 
Back
Top