summary refs log tree commit diff stats
path: root/tests/run
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-11-05 08:36:44 +0100
committerAraq <rumpf_a@web.de>2012-11-05 08:36:44 +0100
commit865d9cc6e6df872f7fa1a32536a3ae42c0384d51 (patch)
tree97e1c47dbaa15a54c9ab78275a78292bb0688fae /tests/run
parent42c8fd1fe2e8a045741c18cd02f9410cb7a990f8 (diff)
downloadNim-865d9cc6e6df872f7fa1a32536a3ae42c0384d51.tar.gz
added system.onRaise to support a condition system
Diffstat (limited to 'tests/run')
-rw-r--r--tests/run/tonraise.nim34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/run/tonraise.nim b/tests/run/tonraise.nim
new file mode 100644
index 000000000..1a555dd94
--- /dev/null
+++ b/tests/run/tonraise.nim
@@ -0,0 +1,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()