NullReferenceException thrown even though checking for Nothing
I have some rather straightforward code for a Compare Function
Public Overridable Function Comparer(thisValue As Object, otherValue
As Object) As Integer
Try
If thisValue Is Nothing Then
If otherValue Is Nothing Then
Return 0
Else
Return -1
End If
Else
If otherValue Is Nothing Then
Return 1
Else
Return thisValue.ToString.CompareTo(otherValue.ToString)
End If
End If
Catch ex As Exception
Return 0
End Try
End Function
The reason for the try-catch block is: I get a NullReferenceException at
the actual comparision line if thisValue is Nothing. The debugger shows me
that thisValue is "Nothing" but lands in the ELSE branch anyway.
Can anyone tell me why?
No comments:
Post a Comment