Skip to content

CkTextException

What CkText throws — only when asked.

Raised by any CkText method called with throwIfInvalid: true when neither the value nor the fallback can be used. Never thrown otherwise: by default every CkText method answers empty, null or a mask's placeholder instead — and ToStringOrNull 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:

CkText.Digits: cannot use "abc" (String) as digits — not between 1 and 64 digits.

Properties

Property Type What it holds
Expected string What the value was meant to be — "usable text", "digits", "a number written as text".
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
{
    CkText.Digits(
        input: "abc",
        throwIfInvalid: true
    );
}
catch (CkTextException error)
{
    Console.WriteLine(error.Reason);    // -> "not between 1 and 64 digits"
    Console.WriteLine(error.Expected);  // -> "digits"
}