summary refs log tree commit diff stats
path: root/tests/exception
diff options
context:
space:
mode:
authorLemonBoy <LemonBoy@users.noreply.github.com>2019-02-08 11:57:47 +0100
committerAndreas Rumpf <rumpf_a@web.de>2019-02-08 11:57:47 +0100
commit710cfcecd30a779a38a1196fd031200ad8a8fe9b (patch)
tree17cadd065653045e1b980e2d46849bdbf15eaad2 /tests/exception
parent631a8ab57f6935d34d290089b7cc36d23dc03504 (diff)
downloadNim-710cfcecd30a779a38a1196fd031200ad8a8fe9b.tar.gz
Rework exception handling in the VM (#10544)
* Rework exception handling in the VM

Make the safepoint handling more precise and less forgiving.
The new code is clearer and more commented.
Perform cleanup on `return`.
The no-exception-thrown case in a try block should be slightly faster
since we don't parse the whole set of exceptions every time.
More tests.

* Fix silly error that broke a few tests

* Testament doesn't like files having the same name

* Remove test case that failed compilation to js
Diffstat (limited to 'tests/exception')
-rw-r--r--tests/exception/texceptions.nim51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/exception/texceptions.nim b/tests/exception/texceptions.nim
index d63187b0e..7bce32837 100644
--- a/tests/exception/texceptions.nim
+++ b/tests/exception/texceptions.nim
@@ -74,3 +74,54 @@ block: #10417
       moo()
 
   doAssert(bar == 1)
+
+# Make sure the VM handles the exceptions correctly
+block:
+  proc fun1(): seq[int] =
+    try:
+      try:
+        raise newException(ValueError, "xx")
+      except:
+        doAssert("xx" == getCurrentExceptionMsg())
+        raise newException(KeyError, "yy")
+    except:
+      doAssert("yy" == getCurrentExceptionMsg())
+      result.add(1212)
+    try:
+      try:
+        raise newException(AssertionError, "a")
+      finally:
+        result.add(42)
+    except AssertionError:
+      result.add(99)
+    finally:
+      result.add(10)
+    result.add(4)
+    result.add(0)
+    try:
+      result.add(1)
+    except KeyError:
+      result.add(-1)
+    except ValueError:
+      result.add(-1)
+    except IndexError:
+      result.add(2)
+    except:
+      result.add(3)
+
+    try:
+      try:
+        result.add(1)
+        return
+      except:
+        result.add(-1)
+      finally:
+        result.add(2)
+    except KeyError:
+      doAssert(false)
+    finally:
+      result.add(3)
+
+  let x1 = fun1()
+  const x2 = fun1()
+  doAssert(x1 == x2)