M
Mike Hofer
Okay, silly question. Nitpicky, sure, but it bugs me.
Range-checking parameters in a property setter. For example, an Enum
property with one of two possible values:
Public Property MyEnumProperty() As MyEnumType
Get
Return m_myEnumProperty
End Get
Set(ByVal Value As MyEnumType)
If Value <> MyEnumType.Value1 And Value <> MyEnumType.Value2
Then
Throw New ArgumentOutOfRangeException("value")
End If
End Set
End Property
(Tacky code for illustrative purposes only!)
My question is this: When you guys are throwing an ArgumentException
in a property setter, do you specify "value" as the argument to the
exception, or do you use the name of the property?
It would *seem* that the correct answer is "value", the name of the
parameter. However, that's hardly helpful. You have to examine the
stack trace to determine which property threw the exception.
I am sorely tempted to use the property name to simplify defect
resolution. But I'm not sure that's a good idea.
On the other hand, I've considered a separate exception class that
indicates "Invalid property value" or something like that without
muddying the property name/parameter name waters.
So any advice you folks can provide would be appreciated.
Thanks in advance!
Range-checking parameters in a property setter. For example, an Enum
property with one of two possible values:
Public Property MyEnumProperty() As MyEnumType
Get
Return m_myEnumProperty
End Get
Set(ByVal Value As MyEnumType)
If Value <> MyEnumType.Value1 And Value <> MyEnumType.Value2
Then
Throw New ArgumentOutOfRangeException("value")
End If
End Set
End Property
(Tacky code for illustrative purposes only!)
My question is this: When you guys are throwing an ArgumentException
in a property setter, do you specify "value" as the argument to the
exception, or do you use the name of the property?
It would *seem* that the correct answer is "value", the name of the
parameter. However, that's hardly helpful. You have to examine the
stack trace to determine which property threw the exception.
I am sorely tempted to use the property name to simplify defect
resolution. But I'm not sure that's a good idea.
On the other hand, I've considered a separate exception class that
indicates "Invalid property value" or something like that without
muddying the property name/parameter name waters.
So any advice you folks can provide would be appreciated.
Thanks in advance!