1 \ @(#) catch.fth 98/01/26 1.2
2 \ Catch and Throw support
4 \ Lifted from X3J14 dpANS-6 document.
11 : CATCH ( xt -- exception# | 0 )
12 sp@ >r ( xt ) \ save data stack pointer
13 catch-handler @ >r ( xt ) \ save previous handler
14 rp@ catch-handler ! ( xt ) \ set current handler
15 execute ( ) \ execute returns if no throw
16 r> catch-handler ! ( ) \ restore previous handler
17 r> drop ( ) \ discard saved stack pointer
18 0 ( ) \ normal completion
21 : THROW ( ???? exception# -- ???? exception# )
22 ?dup ( exc# ) \ 0 THROW is a no-op
27 ." THROW has noone to catch!" cr
30 rp! ( exc# ) \ restore prev return stack
31 r> catch-handler ! ( exc# ) \ restore prev handler
32 r> swap >r ( saved-sp ) \ exc# on return stack
33 sp! drop r> ( exc# ) \ restore stack
35 \ return to caller of catch
39 : (ABORT) ERR_ABORT throw ;
41 what's abort is old.abort
43 : restore.abort what's old.abort is abort ;
44 if.forgotten restore.abort
51 ." After bad word!" cr
55 ['] naive.word catch .