checkNotNegative method

int checkNotNegative (
  1. int value,
  2. [String? name,
  3. String? message]
)

Check that an integer value is non-negative.

Throws if the value is negative.

If name or message are provided, they are used as the parameter name and message text of the thrown error. If name is omitted, it defaults to index.

Returns value if it is not negative.

Implementation

static int checkNotNegative(int value, [String? name, String? message]) {
  if (value < 0) {
    throw RangeError.range(value, 0, null, name ?? "index", message);
  }
  return value;
}

© 2012 the Dart project authors
Licensed under the Creative Commons Attribution-ShareAlike License v4.0.
https://api.dart.dev/stable/2.13.0/dart-core/RangeError/checkNotNegative.html