Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to make a yield created Iterator Continue to the next item upon an Exception?

Tags:

Is there any way to have a yield created iterator continue to the next item when an exception occurs inside one of the iterator blocks?

This is currently not working:

        Boolean result;
        while (true)
        {
            try
            {
               result =  enumerator.MoveNext(); //Taken from a yield created enumerable
               if (!result) break;
            }
            catch (Exception ex)
            {
                Console.WriteLine("CATCHED...");
                continue;
            }
        }
like image 283
aattia Avatar asked Feb 08 '10 17:02

aattia


1 Answers

No there is not. The generated code for a C# iterator does not support exceptions being thrown. If an exception is thrown the MoveNext operation will not complete and the next call will replay from the same place from the standpoint of the generated iterator code.

like image 102
JaredPar Avatar answered Nov 15 '22 05:11

JaredPar