RosettaCodeData/Task/Detect-division-by-zero/Rebol/detect-division-by-zero-2.rebol
2026-04-30 12:34:36 -04:00

14 lines
422 B
Text

div-check: func [
"Attempt to divide two numbers, report result or errors as needed."
x y
/local result
] [
print either error? result: try [x / y][
["Caught" result/type "error:" result/id]
][ [x "/" y "=" result]]
result
]
div-check 12 2 ; An ordinary calculation.
div-check 6 0 ; This will detect divide by zero.
div-check "7" 0.0001 ; Other errors can be caught as well.