summary refs log tree commit diff stats
path: root/tests/run
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2012-06-03 18:00:45 +0300
committerZahary Karadjov <zahary@gmail.com>2012-06-03 18:00:45 +0300
commit3ce400bb00363a4b207ba966937d26c746d25e1b (patch)
tree5e86238d450afa6fab2aa750000218244eecf402 /tests/run
parentab18654e593085feb92e8f93f5c575d6ce62cda4 (diff)
downloadNim-3ce400bb00363a4b207ba966937d26c746d25e1b.tar.gz
bugfix: finally blocks were not executed when the except block is exited by raise or return
Diffstat (limited to 'tests/run')
-rw-r--r--tests/run/texceptions.nim66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/run/texceptions.nim b/tests/run/texceptions.nim
new file mode 100644
index 000000000..2e6101c2a
--- /dev/null
+++ b/tests/run/texceptions.nim
@@ -0,0 +1,66 @@
+discard """
+  output: '''
+BEFORE
+FINALLY
+
+BEFORE
+EXCEPT
+FINALLY
+RECOVER
+
+BEFORE
+EXCEPT
+FINALLY
+'''
+"""
+
+echo ""
+
+proc no_expcetion =
+  try:
+    echo "BEFORE"
+
+  except:
+    echo "EXCEPT"
+    raise
+
+  finally:
+    echo "FINALLY"
+
+try: no_expcetion()
+except: echo "RECOVER"
+
+echo ""
+
+proc reraise_in_except =
+  try:
+    echo "BEFORE"
+    raise newException(EIO, "")
+
+  except:
+    echo "EXCEPT"
+    raise
+
+  finally:
+    echo "FINALLY"
+
+try: reraise_in_except()
+except: echo "RECOVER"
+
+echo ""
+
+proc return_in_except =
+  try:
+    echo "BEFORE"
+    raise newException(EIO, "")
+
+  except:
+    echo "EXCEPT"
+    return
+
+  finally:
+    echo "FINALLY"
+
+try: return_in_except()
+except: echo "RECOVER"
+