RangeException
PHPERRORCommonValidation

Value out of defined range at runtime

Quick Answer

Throw RangeException for numeric range violations detected at runtime (e.g., percentage outside 0-100).

What this means

Runtime variant of DomainException — thrown when a value falls outside the expected range at runtime (as opposed to a compile-time logic error).

Why it happens
  1. 1Percentage value > 100 from a calculation result
  2. 2Negative absolute temperature from sensor data

Fix

Range guard

Range guard
function setProgress(float $pct): void {
    if ($pct < 0.0 || $pct > 100.0) {
        throw new \RangeException("Progress must be 0–100, got $pct");
    }
    $this->progress = $pct;
}

Why this works

Validating the computed value immediately surfaces data processing bugs.

Code examples
Sensor data guardphp
if ($temp < -273.15) {
    throw new \RangeException("Temperature below absolute zero: $temp K");
}

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PHP errors