Why can't a null-reference exception name the object that has a null reference?

前端 未结 5 2174
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-17 15:48

It seems to me that a lot of my debugging time is spent chasing down null-reference exceptions in complex statements. For instance:

For Each game As IHomeGam         


        
5条回答
  •  北海茫月
    2020-12-17 16:32

    A simple way to catch this for debugging to to place an Assert statement prior to using an object, check for null and output a meaningful message.

提交回复
热议问题