NullReferenceException Message Feature Request

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm guessing that NullReferenceExceptions are by far the most common exceptions thrown in .net.

Why not add the type of the reference to the message? Have it say something like:
Object reference of type 'string' not set to an instance of an object.

This would really help when trying to figure out where the null reference is happening.

I've just spent the last two days finding a null reference that happens very intermittently. Having the type would have saved me many hours.

In addition to just the type, you might be able to use reflection to give a property name or variable name.

Bryan Livingston
Alphora.com
 
Please tell me you have exceptions set to 'break' in the debugger.... if you
do, it's usually absolutely obvious what the null reference should have
been.

Bryan Livingston said:
I'm guessing that NullReferenceExceptions are by far the most common exceptions thrown in .net.

Why not add the type of the reference to the message? Have it say something like:
Object reference of type 'string' not set to an instance of an object.

This would really help when trying to figure out where the null reference is happening.

I've just spent the last two days finding a null reference that happens
very intermittently. Having the type would have saved me many hours.
In addition to just the type, you might be able to use reflection to give
a property name or variable name.
 
Cheeky... they're off by default which seems odd to me.
The options are under Debug -> Exceptions, and I usually have all set to
break (with a few exceptions).
I think the exception already does have the stack trace in it, so even if
you're not running under the debugger you could log the stack trace of an
exception which reaches a certain level.
 
Back
Top