( try day 01.06.2001 )

: ndrop 1+ cells sp@ + sp! ;

: try ( c: -- orig dest )
   ?comp
   [compile] ahead
   <mark
   ['] ndrop t> w@ t-w,
; immediate

: (try); ( c: orig dest -- )
   postpone exit
   >r [compile] then r>
   [compile] literal
   postpone catch
;

: finally ( -- n )
  (try); 11
; immediate

: except ( -- n )
  (try); 
  postpone ?dup
  postpone if 12
; immediate

: end-try
  12 = if postpone then then
; immediate

\eof

: test0
   1 2 3
   try
     2drop  drop
     -10 throw
   finally
     if \ drop garbage if there was 'throw'
        2drop drop 
     then
     \ !!! after crash 'finally' restores
     \ only stacks depth, but not stack's data.
     \ That's why we should drop garbage
   end-try
;

: test
   try
     noop
   finally
     . ( ret code )
   end-try
;

: test2
   try
     -10 throw
   finally
     . ( ret code )
   end-try
;