CkCountryException
What CkCountry throws — only when asked.
Raised by any CkCountry method called with
throwIfInvalid: true when neither the value nor the fallback can be used. Never
thrown otherwise: by default those methods answer '' instead. Final, 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:
CkCountry.Alpha2: cannot use "Alasca" (String) as a country — not a recognised country or code.
Properties
Every property is public readonly.
| Property | Type | What it holds |
|---|---|---|
Expected |
string |
What the value was meant to be — 'a country'. |
Input |
mixed |
From CkException: the value that failed, untouched. |
Reason |
string |
From CkException: why, in a few words. |
Quick look
use SafeCoder\CommonKit\CkCountry;
use SafeCoder\CommonKit\Exceptions\CkCountryException;
try {
CkCountry::Alpha2(
input: 'Alasca',
throwIfInvalid: true
);
} catch (CkCountryException $error) {
echo $error->Reason; // -> 'not a recognised country or code'
echo $error->Expected; // -> 'a country'
}