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, and Has and
MissingKeys never throw at all. 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 getPrevious(), the standard slot for the exception behind an
exception. A final class, derived from CkException.
The message names the method, shows the key with its type, and says why the read failed:
CkDictionary.Integer: 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 |
mixed |
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
use SafeCoder\CommonKit\CkDictionary;
use SafeCoder\CommonKit\Exceptions\CkDictionaryException;
$payload = ['name' => 'Mary'];
try {
CkDictionary::Integer(
dictionary: $payload,
key: 'age',
throwIfInvalid: true
);
} catch (CkDictionaryException $error) {
echo $error->Key; // -> 'age'
echo $error->Reason; // -> 'no entry under the key'
}