File: tv2_raise.nim

package info (click to toggle)
nim 2.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,951,160 kB
  • sloc: sh: 24,599; ansic: 1,771; python: 1,493; makefile: 1,013; sql: 298; asm: 141; xml: 13
file content (53 lines) | stat: -rw-r--r-- 696 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
discard """
  valgrind: true
  cmd: '''nim c -d:nimAllocStats --newruntime $file'''
  output: '''OK 3
(allocCount: 7, deallocCount: 4)'''
"""

import strutils, math
import system / ansi_c

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

#  bug #11577

proc newError*: owned(ref Exception) {.noinline.} =
  new(result)

proc mainC =
  raise newError()

try:
  mainC()
except:
  inc ok

echo "OK ", ok
echo getAllocStats()