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
For languages like Java that are compiled to bytecode that gets interpreted by a VM, suppose you have a class X
with a field x
, and its value is null
for a certain reference. If you write
x.foo()
the bytecode might look like this:
push Xref >> top of stack is ref to instance of X with X.x = null
getField x >> pops Xref, pushes 'null' on the stack
invokeMethod foo >> pops 'null' -> runtime exception
The point is that the operation that needs a non-null reference on the stack to operate on it, like invokeMethod in the example, cannot and does not know where that null reference came from.