Guid.parseString constructor
Guid.parseString(
- String guid
Initializes a new instance of the Guid structure by using the value represented by the specified string.
If the guid
does not contain a valid literal,
optionally prefixed by a sign, a FormatException is thrown.
Instead of throwing and immediately catching the FormatException, instead use tryParseString to handle a parsing error.
Implementation
factory Guid.parseString(String guid) {
if (guid.isEmpty) {
throw FormatException('Value "$guid" is empty');
}
if (_Guid.isValidGUID(fromString: guid)) {
return Guid._(GuidValue(guid, _Guid.parse(guid)));
} else {
throw FormatException('Value "$guid" is not a valid GUID');
}
}