在我看来,我的很多调试时间都花在了追踪复杂语句中的空引用异常上。例如:
For Each game As IHomeGame in _GamesToOpen.GetIterator()
为什么,当我得到 NullReferenceException 时,我可以得到堆栈跟踪中的行号,而不是等于 null 的对象的名称。换句话说,为什么:
Object reference not set to an instance of an object.
代替
_GamesToOpen is not set to an instance of an object.
或者
Anonymous object returned by _GamesToOpen.GetIterator() is null.
或者
game was set to null.
这是严格的设计选择,旨在保护代码的匿名性,还是编译器设计中有令人信服的理由不将此信息包含在调试时异常中?