On Wednesday, 3 April 2013 at 08:37:32 UTC, deadalnix wrote:
On Tuesday, 2 April 2013 at 20:11:31 UTC, Lars T. Kyllingstad wrote:
No. To call front on an empty range is a programming error, plain and simple. It's like trying to access the first element of an empty array. The fact that some ranges may allow it anyway does not change anything.


It is illegal for a reason. For instance, with an array, it is an out of bound access. I see ne benefice to hide this information in a more generic RangeError. This is hiding information and providing nothing more.

For arrays, RangeError is synonymous with "out of bounds". I see no reason to invent a new class just for this purpose.

And note that I'm not saying that ranges should be restricted to *only* throwing RangeErrors. Generally, it should be used in situations that are analogous to out of bounds for arrays, such as trying to pop past the end of the range.

However, some ranges may want to do something else in this situation. An output range that writes to a file, for instance, may want to throw a "disk full" exception. A wrapper range may simply propagate any errors from the underlying range.

RangeError is for the cases when it is not possible/necessary to provide more detail than "you tried to call popFront on an empty range, which is illegal".

Lars

Reply via email to