indexRangeError function
The RangeError the platform raises for an out-of-range index.
A plain RangeError, deliberately not an IndexError. IndexError is a
RangeError subtype and looks like the better fit, but the SDK's List.[]
does not use it: the VM raises a plain RangeError, and on IndexError does
not catch an out-of-range list access. Raising IndexError here would
make d4rt strictly more catchable than the platform, so a script written
against d4rt with on IndexError would break once compiled.
length may be 0, in which case end is -1 — below start.
RangeError.range accepts that and reports "Valid value range is empty",
matching what the platform says for an empty container.
Implementation
RangeError indexRangeError(int index, int length) =>
RangeError.range(index, 0, length - 1, 'index');