0

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?

leppie
  • 115,091
  • 17
  • 196
  • 297
Aadam
  • 1,521
  • 9
  • 30
  • 60

3 Answers3

2

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

System.Diagnostics.Debug.Print(col1.ToString());
lc.
  • 113,939
  • 20
  • 158
  • 187
1

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?

Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117
  • I know that problem but i asked for diffrent solution, I think first answer is somewhat related, thanks – Aadam Feb 22 '13 at 06:54
0

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

Manish
  • 510
  • 2
  • 12