I re-implemented Enumerable.Zip
(mine is called Merge
). It is the same as the original, except if one enumerator's MoveNext
returns false before the other (indicating the sequences are not of the same length), it throws an exception.
My question is: What would be the most appropriate exception from the BCL to throw here? (I want this to closely mimic the rest of the Enumerable
(LINQ) functions.)
I think that since your second array will be an argument. So
System.ArgumentOutOfRangeException
Subclass of ArgumentException that’s thrown when a (usually numeric) argument is too big or too small. For example, this is thrown when passing a negative number into a function that accepts only positive values.
OR may be
System.InvalidOperationException
Thrown when the state of an object is unsuitable for a method to successfully execute, regardless of any particular argument values. Examples include reading an unopened file or getting the next element from an enumerator where the underlying list has been modified partway through the iteration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With