checkValidIndex method

void checkValidIndex(int index, indexable, [ String name, int length, String message ])

Check that a value is a valid index into an indexable object.

Throws if index is not a valid index into indexable.

An indexable object is one that has a length and a and index-operator [] that accepts an index if 0 <= index < length.

If length is provided, it is used as the length of the indexable object, otherwise the length is found as indexable.length.

Source

static void checkValidIndex(int index, var indexable,
    [String name, int length, String message]) {
  if (length == null) length = indexable.length;
  // Comparing with `0` as receiver produces better dart2js type inference.
  if (0 > index || index >= length) {
    if (name == null) name = "index";
    throw new RangeError.index(index, indexable, name, message, length);
  }
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dartlang.org/stable/1.24.3/dart-core/RangeError/checkValidIndex.html