texceptions.nim 558 B

123456789101112131415161718192021222324252627282930
  1. discard """
  2. cmd: '''nim c --gc:arc $file'''
  3. output: '''0'''
  4. """
  5. proc other =
  6. raise newException(ValueError, "stuff happening")
  7. proc indirectViaProcCall =
  8. var correct = 0
  9. for i in 1 .. 20:
  10. try:
  11. other()
  12. except:
  13. let x = getCurrentException()
  14. correct += ord(x of ValueError)
  15. doAssert correct == 20
  16. proc direct =
  17. for i in 1 .. 20:
  18. try:
  19. raise newException(ValueError, "stuff happening")
  20. except ValueError:
  21. discard
  22. let mem = getOccupiedMem()
  23. indirectViaProcCall()
  24. direct()
  25. echo getOccupiedMem() - mem