Skip to content

CkUSException

What CkUS throws — only when asked.

Raised by any CkUS method called with throwIfInvalid: true when neither the value nor the fallback can be used. Never thrown otherwise: by default those methods answer "" (the …Mask methods take no throwIfInvalid at all — they never throw and answer their placeholder) instead. 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:

CkUS.Ssn: cannot use "12" (String) as a Social Security number — not in a supported layout.

Properties

Property Type What it holds
Expected string What the value was meant to be — "a Social Security number", "a routing number", "a ZIP code".
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
{
    CkUS.Ssn(
        input: "12",
        throwIfInvalid: true
    );
}
catch (CkUSException error)
{
    Console.WriteLine(error.Reason);    // -> "not in a supported layout"
    Console.WriteLine(error.Expected);  // -> "a Social Security number"
}