UUIDParsingException

This exception is thrown if an error occurs when parsing a UUID from a string.

class UUIDParsingException : Exception {}

Members

Enums

Reason
enum Reason

The reason why parsing the UUID string failed (if known)

Variables

input
string input;

The original input string which should have been parsed.

position
size_t position;

The position in the input string where the error occurred.

reason
Reason reason;

The reason why parsing the UUID string failed (if known)

Examples

import std.exception : collectException;

const inputUUID = "this-is-an-invalid-uuid";
auto ex = collectException!UUIDParsingException(UUID(inputUUID));
assert(ex !is null); // check that exception was thrown
assert(ex.input == inputUUID);
assert(ex.position == 0);
assert(ex.reason == UUIDParsingException.Reason.tooLittle);

uuidv7

import std.datetime : DateTime, SysTime;

SysTime st = DateTime(2025, 8, 19, 10, 38, 45);
UUID u = UUID(st);
assert(u.uuidVersion == UUID.Version.timestampRandom);
SysTime o = u.v7Timestamp();
assert(o == st, st.toString() ~ " | " ~ o.toString());
string s = u.toString();
UUID u2 = UUID(s);
SysTime o2 = u2.v7Timestamp();
assert(o2 == st, st.toString() ~ " | " ~ o2.toString());

uuid v7 generated by external tool

import std.datetime : DateTime, SysTime;
UUID u = UUID("0198c2b2-c5a8-7a0f-a1db-86aac7906c7b");
auto d = DateTime(2025,8,19);
assert((cast(DateTime) u.v7Timestamp()).year == d.year);

Meta