error method
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
Never error(String message, {Match? match, int? position, int? length}) {
validateErrorArgs(string, match, position, length);
if (match == null && position == null && length == null) match = lastMatch;
position ??= match == null ? this.position : match.start;
length ??= match == null ? 0 : match.end - match.start;
final sourceFile = SourceFile.fromString(string, url: sourceUrl);
final span = sourceFile.span(position, position + length);
throw StringScannerException(message, span, string);
}