Is there a way to make a performance created Iterator Continue to the next item on an Exception?

advertisements

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;
            }
        }


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.