Skip to content

CkMoneyException

What CkMoney throws — only when asked.

Raised by any CkMoney method called with throwIfInvalid: true when a value could not be used. Never thrown otherwise: by default every method answers the caller's fallback instead — and AmountOrNull cannot raise it at all: it takes no throwIfInvalid and never throws, null is its answer for any error. 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:

CkMoney.MinorUnits: cannot use "N/A" (String) as an amount of money — letters in the amount.

Properties

Property Type What it holds
Expected string What the value was meant to be — "an amount of money", "a currency code".
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
{
    CkMoney.Amount(
        input: "N/A",
        throwIfInvalid: true
    );
}
catch (CkMoneyException error)
{
    Console.WriteLine(error.Reason);    // -> "letters in the amount"
    Console.WriteLine(error.Expected);  // -> "an amount of money"
}