From eb78b40c04fd1d78cdb0a3050575c9acdf4c6cbb Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Fri, 4 Nov 2016 08:51:09 +1300 Subject: [PATCH] Added exception handling words. --- catch-throw.4th | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 catch-throw.4th diff --git a/catch-throw.4th b/catch-throw.4th new file mode 100644 index 0000000..5c66df3 --- /dev/null +++ b/catch-throw.4th @@ -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> +; -- 2.20.1