RosettaCodeData/Task/Detect-division-by-zero/Nim/detect-division-by-zero.nim
2016-12-05 23:44:36 +01:00

12 lines
332 B
Nim

# In debug builds division by zero exceptions are thrown by default, in release
# builds not. We can still enable them explicitly.
{.push overflowChecks: on.}
proc divCheck(x, y): bool =
try:
discard x div y
except DivByZeroError:
return true
return false
{.pop.} # Restore default check settings
echo divCheck(2, 0)