Last active
January 17, 2018 17:26
-
-
Save hbulens/991f60b4a456b24a1ad5ec8da0a98e14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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