Skip to content

CkGeoException

What CkGeo throws — only when asked.

Raised by any CkGeo method called with throwIfInvalid: true when a value could not be used. Never thrown otherwise: by default every CkGeo method returns its fallback — or the North Pole — instead. LatitudeOrNull and LongitudeOrNull cannot raise it at all: they take no throwIfInvalid and never throw — null is their 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:

CkGeo.Latitude: cannot use "abc" (String) as a latitude — not a number or degrees, minutes and seconds.

Properties

Property Type What it holds
Expected string What the value was meant to be — "a latitude", "the first longitude", "the distance".
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
{
    CkGeo.Latitude(
        input: "abc",
        throwIfInvalid: true
    );
}
catch (CkGeoException error)
{
    Console.WriteLine(error.Reason);    // -> "not a number or degrees, minutes and seconds"
    Console.WriteLine(error.Expected);  // -> "a latitude"
}