Browse project documentation

Errors and exceptions

Daynumv1.0.0-beta.4View sourceEnglish / Persian

Handle date, parsing, timezone and range errors at the right boundary.

All library-defined exceptions live in Eram\Daynum\Exception and implement the DaynumException marker interface. Catch a specific class for recovery; use the marker at an application boundary when all Daynum failures share a policy. It does not include PHP TypeError, JSON errors or exceptions thrown by your own locale implementations.

Exception reference

ExceptionTypical triggerHandling
InvalidDateExceptionInvalid date/time or construction yearReject/correct input; use tryFrom…() for nullable validation
ParseExceptionFormat mismatch, invalid parsed date, range or weekdayShow input guidance; tryParseExact() returns null
InvalidArgumentExceptionUnknown locale/digit style, invalid week start or array shapeFix configuration or input mapping
MissingTimezoneExceptionTimestamp/timezone token with no labelSupply the intended zone, not an arbitrary server default
InvalidTimezoneExceptionNative conversion with an unknown timezoneValidate application zone selection
UmmAlQuraOutOfRangeExceptionConstruction, calendar reading or month/year arithmetic beyond the tableExplicitly select another calendar or reject
WeekAtBoundaryExceptionWeek calculation needs an unsupported Thursday/yearOmit the week label or handle that boundary

Invalid-date parsing

parseExact() wraps calendar exceptions, including Umm al-Qura range errors, in ParseException. tryParseExact() catches only that class, so an unknown locale still throws:

<?php
require 'vendor/autoload.php';

use Eram\Daynum\Calendar\Gregorian\GregorianView;
use Eram\Daynum\Exception\DaynumException;

try {
    GregorianView::tryParseExact('2026-04-08', 'Y-m-d', locale: 'xx');
} catch (DaynumException $e) {
    echo get_class($e), "\n";
}
Eram\Daynum\Exception\InvalidArgumentException

UmmAlQuraOutOfRangeException

Do not use isValidHijri() === false as proof that a date merely needs a civil fallback: invalid months/days produce the same result. See explicit calendar handling.

The library’s InvalidArgumentException, InvalidDateException and ParseException extend PHP’s \InvalidArgumentException; the latter two are not subclasses of Daynum’s own InvalidArgumentException. Catch the marker or the intended concrete types. Exact exception messages are diagnostic text, not a structured error-code API.

Search documentation

Search across all projects. Close this window to return to your guide.

Tab to navigate · Enter to openEsc to close