Skip to content

CkDictionaryException

What CkDictionary throws — only when asked.

Raised by any CkDictionary method called with throwIfInvalid: true when the entry was missing or its value could not be read. Never thrown otherwise: by default those methods answer their fallback instead. When one of the library's own readers rejected the value — say CkNumber refused the text under the key — that reader's exception rides in InnerException, the standard .NET slot for the exception behind an exception. Sealed, and derived from CkException.

The message names the method, shows the key with its type, and says why the read failed:

CkDictionary.Int32: cannot read key "age" (String) — no entry under the key.

Properties

Property Type What it holds
Key string? The key that was looked up, exactly as it was passed in.
Input object? From CkException: the value found under the key, untouched; null when no entry was found.
Reason string From CkException: why, in a few words.

Quick look

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

var payload = new Dictionary<string, object?> { ["name"] = "Mary" };

try
{
    CkDictionary.Int32(
        dictionary: payload,
        key: "age",
        throwIfInvalid: true
    );
}
catch (CkDictionaryException error)
{
    Console.WriteLine(error.Key);     // -> "age"
    Console.WriteLine(error.Reason);  // -> "no entry under the key"
}