tv2_raise.nim 696 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. discard """
  2. valgrind: true
  3. cmd: '''nim c -d:nimAllocStats --newruntime $file'''
  4. output: '''OK 3
  5. (allocCount: 7, deallocCount: 4)'''
  6. """
  7. import strutils, math
  8. import system / ansi_c
  9. proc mainA =
  10. try:
  11. var e: owned(ref ValueError)
  12. new(e)
  13. e.msg = "message"
  14. raise e
  15. except Exception as e:
  16. raise
  17. proc main =
  18. raise newException(ValueError, "argh")
  19. var ok = 0
  20. try:
  21. mainA()
  22. except ValueError:
  23. inc ok
  24. except:
  25. discard
  26. try:
  27. main()
  28. except ValueError:
  29. inc ok
  30. except:
  31. discard
  32. # bug #11577
  33. proc newError*: owned(ref Exception) {.noinline.} =
  34. new(result)
  35. proc mainC =
  36. raise newError()
  37. try:
  38. mainC()
  39. except:
  40. inc ok
  41. echo "OK ", ok
  42. echo getAllocStats()