summary refs log tree commit diff stats
path: root/tests/destructor/tgotoexceptions8.nim
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2020-03-17 23:18:43 +0100
committerGitHub <noreply@github.com>2020-03-17 23:18:43 +0100
commitfe7b1dfb2a7a5a7e66dc0870b50d4f93259da875 (patch)
tree31d394c2c90bb3e1898d20fb80c7b68d9415d451 /tests/destructor/tgotoexceptions8.nim
parentb737bb4be0956f8dce69ec8b7ccfe624890abaa5 (diff)
downloadNim-fe7b1dfb2a7a5a7e66dc0870b50d4f93259da875.tar.gz
rewritten goto based exception handling; much cleaner implementation;… (#13677)
* rewritten goto based exception handling; much cleaner implementation; fixes #13668
Diffstat (limited to 'tests/destructor/tgotoexceptions8.nim')
-rw-r--r--tests/destructor/tgotoexceptions8.nim69
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/destructor/tgotoexceptions8.nim b/tests/destructor/tgotoexceptions8.nim
new file mode 100644
index 000000000..e968cdce2
--- /dev/null
+++ b/tests/destructor/tgotoexceptions8.nim
@@ -0,0 +1,69 @@
+discard """
+  output: '''A
+B
+X
+inner finally
+Y
+outer finally
+msg1
+msg2
+finally2
+finally1'''
+  cmd: "nim c --gc:arc $file"
+"""
+
+# bug #13668
+
+proc main =
+  try:
+    try:
+      raise newException(IOError, "IOError")
+
+    except:
+      echo "A"
+      raise newException(CatchableError, "CatchableError")
+
+  except:
+    echo "B"
+    #discard
+
+proc mainB =
+  try:
+    try:
+      raise newException(IOError, "IOError")
+
+    except:
+      echo "X"
+      raise newException(CatchableError, "CatchableError")
+    finally:
+      echo "inner finally"
+
+  except:
+    echo "Y"
+    #discard
+  finally:
+    echo "outer finally"
+
+main()
+mainB()
+
+when true:
+  #bug 7204
+  proc nested_finally =
+    try:
+      raise newException(KeyError, "msg1")
+    except KeyError as ex:
+      echo ex.msg
+      try:
+        # pop exception
+        raise newException(ValueError, "msg2") # push: exception stack (1 entry)
+      except:
+        echo getCurrentExceptionMsg()
+        # pop exception (except)
+      finally:
+        echo "finally2"
+      # pop exception (except KeyError as ex)
+    finally:
+      echo "finally1"
+
+  nested_finally()