Is there any way to find out which object caused the NullReferenceException?

后端 未结 3 1571
独厮守ぢ
独厮守ぢ 2021-01-12 13:14

Is there any way to find the object name that caused the control to flow into the catch block from a NullReferenceException, so that we can easily debug by giving an alert o

3条回答
  •  -上瘾入骨i
    2021-01-12 13:46

    (NOTE: The answer is for the original question, before it was edited four years after the fact)

    What is an object's name? It's a design-time token to us, programmers, which identifies the object reference, but it has meaning only until compilation.

    Some objects have a dedicated Name property but that does not (and should not) have anything to do with the name of the object reference in code, it's the visual designer's courtesy to name object references after the Name property, but it's a convention rather than a requirement. Besides, a null reference cannot have Name property simply because the reference is null, it's not yet assigned to any object that has a readable Name.

提交回复
热议问题