public static IEnumerable <SelectTryResult <TSource, TResult> > SelectTry <TSource, TResult>(this IEnumerable <TSource> enumerable, Func <TSource, TResult> selector) { foreach (TSource element in enumerable) { SelectTryResult <TSource, TResult> returnedValue; try { returnedValue = new SelectTryResult <TSource, TResult>(element, selector(element), null); } catch (Exception ex) { returnedValue = new SelectTryResult <TSource, TResult>(element, default(TResult), ex); } yield return(returnedValue); } }