CkDateTimeException
What CkDateTime throws — only when asked.
Raised by any CkDateTime method called with
throwIfInvalid: true when neither the value nor the fallback can be used. Never
thrown otherwise: by default those methods answer their fallback — or the year-one
sentinel — instead. The OrNull twins cannot raise it at all: they take no
throwIfInvalid and never throw — null is their 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:
CkDateTime.ToDateTime: cannot use "31/12/2026 14:05" (String) as a moment in time — not a date in month-first order.
Properties
| Property | Type | What it holds |
|---|---|---|
Expected |
string |
What the value was meant to be — "a moment in time", "a time of day", "a time zone". |
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
{
// day 31 cannot be a month, so month-first reading fails
CkDateTime.ToDateTime(
input: "31/12/2026 14:05",
throwIfInvalid: true
);
}
catch (CkDateTimeException error)
{
Console.WriteLine(error.Reason); // -> "not a date in month-first order"
Console.WriteLine(error.Expected); // -> "a moment in time"
}