NullReferenceException Message Feature Request

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
 
S

Stu Smith

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.
 
S

Stu Smith

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top