using System.Collections.Generic;
public static void Main()
PerformCallAndHandleExceptions(() => ThrowingEnumerable(true));
Console.WriteLine("The call didn't throw. This is bad.");
Console.WriteLine("The call threw before enumaration. The fix worked!");
private static IEnumerable<TResult> PerformCallAndHandleExceptions<TResult>(Func<IEnumerable<TResult>> performCall)
return PerformCallAndHandleExceptions<IEnumerable<TResult>>(() => performCall().PeekFirst());
private static TResult PerformCallAndHandleExceptions<TResult>(Func<TResult> performCall)
private static IEnumerable<bool> ThrowingEnumerable(bool shouldThrow)
throw new Exception("Flute!");
public static class EnumerableExtension
public static IEnumerable<T> PeekFirst<T>(this IEnumerable<T> e)