M Mozhi v3.7.0 code

Error reference › Runtime diagnostics

RUNTIME002

division by zero

error
verifiedverified on v3.7.0 categoryruntime terminalstable code

What it means

Integer and float division by zero is undefined in Mozhi and reported instead of producing infinity or crashing.

Trigger condition

A `/` or `%` operation has a zero right-hand side.

Minimal failing example

let n = 0
echo(10 / n)

Verified fix

let n = 0
if n != 0 { echo(10 / n) } else { echo("n is zero") }

Guard the divisor, or use a fallback value.

What the interpreter prints

error[RUNTIME002]: division by zero
  --> app.mz:1:16
 1 | let n = 0
   |                 ^
   |
reason: (the exact problem, with positions)
help:   (a suggested fix appears here)
docs:   https://crossberry-in.github.io/mozhi-doc/errors/RUNTIME002
Run mozhi --json run app.mz to get the same information as machine-readable JSON (schema mozhi.diagnostics.v1), or --verbose to also show grouped related diagnostics. See the CLI reference.

Suggested fix

Check the divisor before dividing; for user input, validate with a condition first.

Related syntax

Arithmetic operators

Related diagnostics

RUNTIME001

Reference links

Limitations

Float division also rejects zero (Mozhi does not produce IEEE infinities).