Detecting what the target object is when NullReferenceException is thrown

后端 未结 10 848
时光说笑
时光说笑 2020-12-03 01:18

I\'m sure we all have received the wonderfully vague \"Object reference not set to instance of an Object\" exception at some time or another. Identifying the object that is

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 01:52

    There's really not much you can do besides look at the stack trace; if you're dereferencing multiple object references in the same line of code, there's no way to determine which one is null without setting a breakpoint. You could avoid this by only dereferencing one object per line, but that would result in some pretty terrible-looking code.

提交回复
热议问题