DIP33: A standard exception hierarchy

Jonathan M Davis jmdavisProg at gmx.com
Wed Apr 3 11:08:08 PDT 2013


On Wednesday, April 03, 2013 10:37:31 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.

RangeError _is_ out-of-bounds-access. Range in this context has nothing to do 
with ranges in the D sense (though that would be a good argument for changing 
it to something more like OutOfBoundsError).

I'm not sure that I'd use RangeError for the popFront case (if I didn't, I'd 
just a normal assertion), but I don't think that it's necessarily wrong or at 
all bad to use a RangeError in that case. We've definitely started moving 
towards using RangeError in version(assert) blocks for opIndex and opSlice in 
std.range and std.algorithm. And we're doing that precisely to make them act 
more like arrays.

- Jonathan M Davis


More information about the Digitalmars-d mailing list