I have one line of code that throws an exception, and when the catch(Exception ex) line executes, ex is NULL. Am I interpreting this correctly? If this is happening, does anyone have an idea of how this could occur? I am using a lot of Telerik RAD controls, could that be causing an issue?

In the Watch window this information displays:
Name: ex
Value: Object reference not set to an instance of an object

`try
{
    RadScriptManager sm = new RadScriptManager();
    sm.ID = "ScriptManager1";
}
catch(Exception ex)
{
    System.Console.WriteLine("Error: "+ex.Message);
}`

The exception is thrown when I access sm to set its ID.

Is your break point ON the catch(exception ex) line or past it?

If your break point is ON the catch line the 'ex' variable has not been initiated or assigned yet. Try putting your break point IN your catch block.

If this is not the case could you supply some code? Object regerence not set to an instance of an object means you are trying to do work with data that is null. Without seeing your code it's very difficult to help.

My breakpoint is at line 7. It breaks and then I step one line in (line 8) and then look at the value of ex. That's where I see the null reference type of message.

"Object reference not set to an instance of an object" is the message contained by the Exception, it does not refer to the exception itself. It's telling you that that is the reason the particular line of code threw the exception.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.