Guid.parseBytes constructor

Guid.parseBytes(
  1. Uint8List guid
)

Initializes a new instance of the Guid structure by using the specified array of bytes.

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 tryParseBytes to handle a parsing error.

Implementation

factory Guid.parseBytes(Uint8List guid) {
  if (guid.isEmpty) {
    throw FormatException('Value "$guid" is empty');
  }

  if (_Guid.isValidGUID(fromByteList: guid)) {
    return Guid._(GuidValue(_Guid.unparse(guid), guid));
  } else {
    throw FormatException('Value "$guid" is not a valid GUID');
  }
}