Skip to content

CkEmailException

What CkEmail throws — only when asked.

Raised by any CkEmail method called with throwIfInvalid: true when neither the value nor the fallback can be used. Never thrown otherwise: by default those methods answer "", false or a mask's placeholder 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:

CkEmail.Address: cannot use "bob@" (String) as an email address — not a valid address.

Properties

Property Type What it holds
Expected string What the value was meant to be — "an email address".
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
{
    CkEmail.Address(
        input: "bob@",
        throwIfInvalid: true
    );
}
catch (CkEmailException error)
{
    Console.WriteLine(error.Reason);    // -> "not a valid address"
    Console.WriteLine(error.Expected);  // -> "an email address"
}