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. 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:
CkCountry.Alpha2: cannot use "Alasca" (String) as a country — not a recognised country or code.
Properties
| Property | Type | What it holds |
|---|---|---|
Expected |
string |
What the value was meant to be — "a country". |
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
{
CkCountry.Alpha2(
input: "Alasca",
throwIfInvalid: true
);
}
catch (CkCountryException error)
{
Console.WriteLine(error.Reason); // -> "not a recognised country or code"
Console.WriteLine(error.Expected); // -> "a country"
}