Yield return with try catch, how can I solve it?
Here is a code snippet, which works for me (I did not reach the error condition). while (true) { T ret = null; try { if (!enumerator.MoveNext()) { break; } ret = enumerator.Current; } catch (Exception ex) { // handle the exception and end the iteration // probably you want it to re-throw it break; … Read more