0

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.

Edited by madcour11: code gives me errors

3
Contributors
3
Replies
22
Views
2 Years
Discussion Span
Last Post by hericles
0

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.

0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.