[Other proposals]


Libraries cannot introduce throw values, because they don't know which values are used by other libraries or the application.

The system does not know how to report a new exception.


EXCEPTION ( c-addr u -- n ) exception
n is a previously unused THROW value in the range {-4095...-256}. Consecutive calls to EXCEPTION return consecutive decreasing numbers.

The system may use the string denoted by c-addr u when reporting that exception (if it is not caught).

After a marker is executed or a word is forgotten that was defined before EXCEPTION was called, THROWing n is an ambiguous condition.

Typical Use

s" Out of GC-managed memory" EXCEPTION CONSTANT gc-out-of-memory
... gc-out-of-memory THROW ...


The restriction to values in the range {-4095...-256} ensures that existing standard programs continue to work.

The requirement to return consecutive decreasing THROW values makes it possible to check for whole classes of exceptions with WITHIN:

  DUP lib-last-exception lib-first-exception 1+ WITHIN IF
    ... \ deal with exceptions from lib
    THROW \ just pass the ones on that we don't know how to handle

The ambiguous condition after forgetting allows systems to reclaim exception numbers and the memory taken up by the strings on forgetting. Systems are not required to do this.

Andrew Haley also voiced concerns about the interaction with multitasking systems. This proposal can be integrated with multitasking systems in several ways:


EXCEPTION is implementend in Gforth since before release 0.4.0.

An approximation in ANS Forth is included in the Gforth compat library which is also included in the garbage collector.

EXCEPTION is used in the garbage collector.


Michael L. Gassanenko on experience:
I used:

CREATE not-ready

... IF not-ready THROW ...

BTW, the system(s) that I have to work on have no built-in CATCH .
Peter Knaggs:
another part of your "library" model, most useful.

Anton Ertl