Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I write this cod

for int(I= 0 I<100)
{
}

in I[50] ihave error I want app don't stop and go I[51].but program stop and show message in catch
{
}
solution like resume next in vb6.
sorry for bad English.
Posted

OK, so put the Try/Catch block inside the loop, not outside.
 
Share this answer
 
Comments
Thomas Daniels 7-Jul-13 9:14am    
Comment from the OP, posted as an answer:
im beggner in c# pleace show me by example!
As far as I could understand your question, following 2 probabilities could exist:

1. While iterating in for loop, as soon as you reach i = 50 you get some exceptions that remains unhandled and crashes your application.
In this case best thing is to find out why you are getting that exception. Looking at exception message, and stack trace would be helpful. If at all you can't stop the exception from being raised, you must enclose your code in try catch as below:

C#
for(i=0; i<100;i++)
{

try{

//...your code goes here
}

catch(Exception ex) //Better to replace Exception with exact type of exception that you are getting
{
//Log or handle the exception scenario....
}
}



2. If you have declared I as some array and if you are getting error in I[50] , then most probably length of I is limited to 50 (until and unless you have written your own indexer, which in your case has lowest probability in my opinion).
So you can not get 51st element.

Please confirm that you are getting exception that says something like "Index out of range".

In this case if you want to get to 100 elements then you write something like:

C#
int I =new int[100]


and then iterate on I.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900