Suppose I have a method that takes an object of some kind as an argument. Now say that if this method is passed a null argument, it\'s a fatal error and an exception shoul
I agree with the idea of failing fast - however it is wise to know why failing fast is practical. Consider this example:
void someMethod(SomeClass x)
{
x.Property.doSomething();
}
If you rely on the NullReferenceException
to tell you that something was wrong, how will you know what was null? The stack trace will only give you a line number, not which reference was null. In this example x
or x.Property
could both have been null and without failing fast with aggressive checking beforehand, you will not know which it is.