Open question. Should there be special support for this scenario?
static void Main(string args)
var s1 = Enumerable.Range(1, 10);
var s2 = s1.Select(x => x - 10);
var s3 = Enumerable.Empty<int>();
s3 = s1.Zip(s2, (a, b) => a / b);
catch (DivideByZeroException) // we'd like to catch the insect here
foreach (var x in s3) // but this is where it shows itself
It's quite easy to build extension methods to catch and handle exceptions and chain these on a LINQ expression. It just doesn't follow the normal syntax for dealing with exceptions.
Hmm, well, that's the framework, not C#, but I think the issue here is accepting how enumerables work. If you really need to know
right now that nothing will cause the enumerable to throw then do something to materialize it
right now, like s1.Zip(...).ToArray(). Alternatively, because you know where the exception can happen just put your catch in the right place.