toverflw.nim 351 B

12345678910111213141516171819202122
  1. discard """
  2. file: "toverflw.nim"
  3. output: "the computation overflowed"
  4. """
  5. # Tests nim's ability to detect overflows
  6. {.push overflowChecks: on.}
  7. var
  8. a, b: int
  9. a = high(int)
  10. b = -2
  11. try:
  12. writeLine(stdout, b - a)
  13. except OverflowError:
  14. writeLine(stdout, "the computation overflowed")
  15. {.pop.} # overflow check
  16. #OUT the computation overflowed