3.30 Exceptions

throw ( n -- ) causes an exception unless n is zero.

100 throw .s
0 throw .s

catch ( ... xt -- ... n ) behaves similar to execute, but
it catches exceptions and pushes the number of the exception on the
stack (or 0, if the xt executed without exception). If there was an
exception, the stacks have the same depth as when entering catch:

.s
3 0 ' / catch .s
3 2 ' / catch .s

Assignment: Try the same with execute instead of catch.

Throw always jumps to the dynamically next enclosing
catch, even if it has to leave several call levels to achieve
this:

However, this is still not safe against, e.g., the user pressing
Ctrl-C when execution is between the catch and
restore-x.

Gforth provides an alternative exception handling syntax that is safe
against such cases: try ... restore ... endtry. If the code
between try and endtry has an exception, the stack
depths are restored, the exception number is pushed on the stack, and
the execution continues right after restore.