I am trying to catch an unhandled exception but it still occurs an error. Where do I need to start my "try" and when/how do I need to catch it ? Here is my code:
String allMarks = "";
String toString1 = "";
String toString2 = "";
if (eventcounter.Count > 2)
{
allMarks = allMarks + eventcounter[0];
for (int i = 0; i < eventcounter.Count; i++)
{
toString1 = eventcounter[i].ToString();
for (int j = 1; j <= eventcounter.Count; j++)
{
try
{
toString2 = eventcounter[j].ToString();
}
catch (System.IndexOutOfRangeException)
{
Console.WriteLine("not enough elements to compare");
throw new System.ArgumentOutOfRangeException("Index parameter is out of range");
}
if (toString1 != toString2)//(eventcounter[i] != eventcounter[j])
{
allMarks = allMarks + eventcounter[j];
Console.WriteLine(allMarks);
//_sensorTextView3.Text = string.Format("Eventcounter: {0}", allMarks);
}
}
}
// _sensorTextView3.Text += allMarks;
}
UPDATE: Okay I am using only one loop now instead of two but still the error occurs whenever run the code
for (int i = 0; i < eventcounter.Count; i++)
{
try
{
toString1 = eventcounter[i].ToString();
toString2 = eventcounter[i + 1].ToString();
}
catch (System.IndexOutOfRangeException)
{
throw new System.ArgumentOutOfRangeException("Index parameter is out of range");
}
if (toString1 != toString2)
{
allMarks = allMarks + eventcounter[i+1];
Console.WriteLine(allMarks);
}