summary refs log tree commit diff stats
path: root/tests/exception/tfinally.nim
blob: c5b1dd841432f57c23270f6326ce8a0932a86b1a (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
discard """
  output: '''
came
here
3
msg1
msg2
finally2
finally1
-----------
except1
finally1
except2
finally2
'''
"""
# Test return in try statement:

proc main: int =
  try:
    try:
      return 1
    finally:
      echo("came")
      return 2
  finally:
    echo("here")
    return 3

echo main() #OUT came here 3

#bug 7204
proc nested_finally =
  try:
    raise newException(KeyError, "msg1")
  except KeyError as ex:
    echo ex.msg
    try:
      raise newException(ValueError, "msg2")
    except:
      echo getCurrentExceptionMsg()
    finally:
      echo "finally2"
  finally:
    echo "finally1"

nested_finally()

echo "-----------"
#bug 7414
try:
  try:
    raise newException(Exception, "Hello")
  except:
    echo "except1"
    raise
  finally:
    echo "finally1"
except:
  echo "except2"
finally:
  echo "finally2"