Hello, i want to handle overflow/underflow on int operation of add, sub, mul, and div
Expecting the following to raise overflow, but it did not, it wraps the int value does the compiler helps finding this potentially overflow operations?
Thank you friends!
import strutils
{.overflowChecks: on.}
proc something() =
var input: string
if readLine(stdin, input):
echo "input > ", input
var x = 0'u8
try:
x -= input.parseInt().uint8
x -= 1 # OverflowDefect
x = x - 1 # No error
doAssert(x == 253'u8)
echo x
except OverflowDefect:
echo "overflow!!"
something()