Skip to content

CkUuidException

What CkUuid throws — only when asked.

Raised by any CkUuid method called with throwIfInvalid: true when a value could not be used as a UUID (a universally unique identifier — the 128-bit id .NET calls a Guid). Never thrown otherwise: by default those methods answer "", Guid.Empty, or — for Version — your numeric fallback instead — and ToGuidOrNull cannot raise it at all: it takes no throwIfInvalid and never throws, null is its answer for any error. Sealed, and derived from CkException.

The message names the method, shows the value with its type, says what it was meant to be and why it failed:

CkUuid.Canonical: cannot use "junk" (String) as a UUID — not a UUID in a known shape.

Properties

Property Type What it holds
Expected string What the value was meant to be — "a UUID", "an output shape".
Input object? From CkException: the value that failed, untouched.
Reason string From CkException: why, in a few words.

Quick look

using SafeCoder.CommonKit;
using SafeCoder.CommonKit.Exceptions;

try
{
    CkUuid.Canonical(
        input: "junk",
        throwIfInvalid: true
    );
}
catch (CkUuidException error)
{
    Console.WriteLine(error.Reason);    // -> "not a UUID in a known shape"
    Console.WriteLine(error.Expected);  // -> "a UUID"
}