Nim/tests/destructor/tv2_raise.nim
2019-04-13 10:50:30 +02:00

42 lines
554 B
Nim

discard """
cmd: '''nim c --newruntime $file'''
output: '''OK 2
4 1'''
"""
import strutils, math
import system / ansi_c
import core / allocators
proc mainA =
try:
var e: owned(ref ValueError)
new(e)
e.msg = "message"
raise e
except Exception as e:
raise
proc main =
raise newException(ValueError, "argh")
var ok = 0
try:
mainA()
except ValueError:
inc ok
except:
discard
try:
main()
except ValueError:
inc ok
except:
discard
echo "OK ", ok
let (a, d) = allocCounters()
discard cprintf("%ld %ld\n", a, d)