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 — and neither can TryParse, whose false is the whole signal. A final class, 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 mixed From CkException: the value that failed, untouched.
Reason string From CkException: why, in a few words.

Quick look

use SafeCoder\CommonKit\CkGeo;
use SafeCoder\CommonKit\Exceptions\CkGeoException;

try {
    CkGeo::Latitude(
        input: 'abc',
        throwIfInvalid: true
    );
} catch (CkGeoException $error) {
    echo $error->Reason;     // -> 'not a number or degrees, minutes and seconds'
    echo $error->Expected;   // -> 'a latitude'
}