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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With