Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public static IEnumerable <T> CatchExceptions <T>(this IEnumerable <T> src, Action <Exception> action = null)
{
using(IEnumerator <T> enumerator = src.GetEnumerator())
{
bool next = true;
while (next)
{
try
{
next = enumerator.MoveNext();
}
catch (Exception ex)
{
if (action != null)
action(ex);
continue;
}
if (next)
yield return enumerator.Current;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment