Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hbulens/991f60b4a456b24a1ad5ec8da0a98e14 to your computer and use it in GitHub Desktop.
Save hbulens/991f60b4a456b24a1ad5ec8da0a98e14 to your computer and use it in GitHub Desktop.
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