error method

  1. @alwaysThrows
void error (String message, { Match match, int position, int length })
@alwaysThrows

Throws a FormatException with message as well as a detailed description of the location of the error in the string.

match is the match information for the span of the string with which the error is associated. This should be a match returned by this scanner's lastMatch property. By default, the error is associated with the last match.

If position and/or length are passed, they are used as the error span instead. If only length is passed, position defaults to the current position; if only position is passed, length defaults to 0.

It's an error to pass match at the same time as position or length.

Implementation

@alwaysThrows
void error(String message, {Match match, int position, int length}) {
  validateErrorArgs(string, match, position, length);

  if (match == null && position == null && length == null) match = lastMatch;
  if (position == null) {
    position = match == null ? this.position : match.start;
  }
  if (length == null) length = match == null ? 0 : match.end - match.start;

  var sourceFile = new SourceFile.fromString(string, url: sourceUrl);
  var span = sourceFile.span(position, position + length);
  throw new StringScannerException(message, span, string);
}