Hacker News new | ask | show | jobs
by theforgottenone 4414 days ago
Meh. Using a dummy object doesn't solve the problem of testing if you got the dummy or not. And throwing a specific exception is still an exception, but now more code to maintain, and only for exceptional circumstances (or is it really exceptional?).

Yeah, Null Ref Exception isn't as pretty as a more domain specific one, but the essential thing happens regardless: the program throws as soon as you try to access a member. And if you just pass your results on to another function, that function could be testing its inputs, and throwing your exception there as an explicit ArgumentNull instead of Null Ref.

I prefer less to more code, especially for an error I wont even expect to ever see. If it something I do expect, then sure, make a fancy exception and throw that.