tv2_raise.nim 702 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. discard """
  2. cmd: '''nim c --newruntime $file'''
  3. output: '''OK 3
  4. 5 1'''
  5. """
  6. import strutils, math
  7. import system / ansi_c
  8. import core / allocators
  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. let (a, d) = allocCounters()
  43. discard cprintf("%ld %ld\n", a, d)