c# - When does throwing an exception break a for loop? -


will loop in dosomething break if exception thrown before complete loop.

var test = new test(...)  try{       //do in test       test.dosomething()   }   catch(myexception e)   {      \\do exception   }    class test {    public void dosomething(...)    {          for(var i=0;i < 5; i++)          {                 ...                  if(some smoke)                   {                       throw new myexception {...}                   }                  ...           } } 

you have tested question defining loop , see if can reach point after exception:

void main() {     try{         dosomething();     }     catch{         console.writeline("yup. breaks");     } } void dosomething() {     for(int = 0; <= 1; i++)     {         if(i == 0) {             throw new notimplementedexception();         }         if( != 0)         {             console.writeline("loop continues");         }     } } 

and answer question: no, code breaks, because exception not handled.

if put try/catch block inside loop, can call continue; in catch-block after exception hsa been dealt continue iteration.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -