Delphi / Object Pascal · Exception

ERangeError Exception

What does ERangeError Exception mean in Delphi / Object Pascal?

A descendant of EIntError, raised when an integer expression's value can't fit the declared range of the type it's being assigned to - assigning 300 to a Byte, or an array or string index outside its bounds - under $R+ range checking.

ERangeError ExceptionDelphi (VCL) · Delphi (FireMonkey)

Condition

A descendant of EIntError, raised when an integer expression's value can't fit the declared range of the type it's being assigned to - assigning 300 to a Byte, or an array or string index outside its bounds - under $R+ range checking.

Fix

Compile with range checking enabled during development to catch this early, widen the target type or clamp the value if it can legitimately exceed range, and validate array/string indices before use rather than trusting external input.

Related exception