summary refs log tree commit diff stats
path: root/tests/exception/tonraise.nim
blob: 1a555dd94ec76288a1752d0b2147ea0ba0fa937c (plain) (blame)
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
discard """
  output: '''i: 1
success'''
"""

type
  ESomething = object of E_Base
  ESomeOtherErr = object of E_Base

proc genErrors(s: string) =
  if s == "error!":
    raise newException(ESomething, "Test")
  else:
    raise newException(EsomeotherErr, "bla")

proc foo() =
  var i = 0
  try:
    inc i
    onRaise(proc (e: ref E_Base): bool =
      echo "i: ", i)
    genErrors("errssor!")
  except ESomething:
    echo("ESomething happened")
  except:
    echo("Some other error happened")
    
  # test that raise handler is gone:
  try:
    genErrors("error!")
  except ESomething:
    echo "success"

foo()