PDA

View Full Version : continue the loop despite exception


mariechristine
01-16-2004, 04:10 AM
suppose i have a for loop as shown below. Suppose for i=0, reading the url will result in an operation time out. When that occurs i want the execution to continue the loop for the next i despite the exception. How is that done?

for (int i=0; i<2; i++)
{
//retrieve genus and species
genus=this.dsetFish.FISH.Rows[i]["Genus"].ToString();
species=this.dsetFish.FISH.Rows[i]["Species"].ToString();

System.Net.WebClient client = new System.Net.WebClient();
System.IO.Stream data;
try
{
data = client.OpenRead("http://202.123.56.178//summary//SpeciesSummary.asp?genus=" + genus + "&species=" + species + "");
}
catch(Exception exc)
{
MessageBox.Show(exc.Message);
throw exc ;
}
}

sicarius
01-16-2004, 01:59 PM
well, after you catch the exception it is considered to be handled. So there is no reason for you to be throwing the exception to a higher level in the stack.

Just eliminate the
throw exc;
statement and it should pick up execution after the catch's closing brace.