Aadam
Aadam

Reputation: 1541

writing text to response not working when exception is thrown

I am trying to write some text before the line is throwing the exception, I want to view that text written by response, anyway I cannot see that, but only the exception is shown, Where can I find that text now.. The code below may give a clear picture.

res.Write(col1);
res.Write(colms);
String colName = colms[col1];

Now i am getting this exception at the third line:

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

I want to see those values as shown in code, but that is not working. In Java I used to do something like

System.out.println(col1);

and that will print to the netbeans console. Now i am using VS2010. How to achieve that same here?

Upvotes: 0

Views: 126

Answers (3)

शेखर
शेखर

Reputation: 17614

You asked about the following error

Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index

Problem can be

 String colName = colms[col1];

Index out of range means you are trying to access an index which is not in the range.

Edit 1

You can put break point to see what values are coming in your variable.
Here is good link about break points
http://weblogs.asp.net/scottgu/archive/2010/04/21/vs-2010-debugger-improvements-breakpoints-datatips-import-export.aspx

Edit 2

You can also take benefit of immediate window.

How do you use the Immediate Window in Visual Studio?

Upvotes: 1

Manish
Manish

Reputation: 510

Put your code in try block, you will be able to access col1 in the catch block.

Upvotes: 0

lc.
lc.

Reputation: 116458

You can use Debug.Print to print to an attached debug listener (presumably VS):

System.Diagnostics.Debug.Print(col1.ToString());

Upvotes: 2

Related Questions