Today’s Daily WTF post was one of their funny screenshot articles and one of them struck me as being quite familiar:
Die-hard readers of my blog may be thinking that based on the Diebold logo in the picture, that I’m reminded of one of my rants against slow Diebold ABMs. It’s not. That “Object reference not set to an instance of an object” ASP.NET error is the one that makes me shudder – more so, since this is a banking application.
Sometimes this is caused by trying to access variables and object beyond the current scope, but Visual Studio can notice these more often than not during a build. Where I really get nabbed is when trying to access a null object. Sure, sometimes it’s just a slight oversight on my part and I try to access an objects methods and properties without actually instantiating it first. Hey, it happens. Yet, often I find that an object doesn’t instantiate and I don’t find until much later….like runtime later. So I’m now conditioned to try to catch everything:
MyCoolClass myobject = null;
try
{
myobject = new MyCoolClass();
myobject.someVoidMethod(SOME_CONSTANT);
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
finally
{
myobject = null;
}
That’s my two cents, anyway 😉