Added exception handling words.
authorTim Vaughan <tgvaughan@gmail.com>
Thu, 3 Nov 2016 19:51:09 +0000 (08:51 +1300)
committerTim Vaughan <tgvaughan@gmail.com>
Thu, 3 Nov 2016 19:51:09 +0000 (08:51 +1300)
catch-throw.4th [new file with mode: 0644]

diff --git a/catch-throw.4th b/catch-throw.4th
new file mode 100644 (file)
index 0000000..5c66df3
--- /dev/null
@@ -0,0 +1,23 @@
+\ Exception handling
+
+variable handler
+
+: catch ( cfa -- exception# | 0 )
+    psp@ >R
+    handler @ >R
+    rsp@ handler !
+    execute
+    R> handler !
+    R> drop
+    0
+;
+
+: throw ( ... exception# -- ... exception# )
+    ?dup 0= if exit then
+
+    handler @ rsp!
+    R> handler !
+    
+    R> swap >R
+    psp! drop R>
+;