Delphi / Object Pascal · Exception

EZeroDivide Exception

What does EZeroDivide Exception mean in Delphi / Object Pascal?

The floating-point counterpart to EDivByZero, raised when a real-number division by zero occurs while the FPU's divide-by-zero exception mask is unmasked (the VCL's default state). Code that has changed masking via SetExceptionMask can see 0/0.0 silently return infinity or NaN instead of raising.

EZeroDivide ExceptionDelphi (VCL) · Delphi (FireMonkey)

Condition

The floating-point counterpart to EDivByZero, raised when a real-number division by zero occurs while the FPU's divide-by-zero exception mask is unmasked (the VCL's default state). Code that has changed masking via SetExceptionMask can see 0/0.0 silently return infinity or NaN instead of raising.

Fix

Guard divisors that come from calculations such as averages, ratios, or per-unit costs with an explicit zero check, and be deliberate about calling System.Math.SetExceptionMask only where IEEE-754 infinity/NaN semantics are actually wanted instead of an exception.

Related exception