MAE/1
M. Anton Ertl (anton@mips.complang.tuwien.ac.at)
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.
n is a previously unusedEXCEPTION( c-addr u -- n ) exceptionTHROWvalue in the range {-4095...-256}. Consecutive calls toEXCEPTIONreturn consecutive decreasing numbers.The system may use the string denoted by c-addr u when reporting that exception (if it is not caught).
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
THROWvalues makes it possible to check for whole classes of exceptions withWITHIN:... CATCH ?DUP IF DUP lib-last-exception lib-first-exception 1+ WITHIN IF ... \ deal with exceptions from lib ELSE THROW \ just pass the ones on that we don't know how to handle THEN
EXCEPTIONis 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.
- Michael L. Gassanenko:
- I used:
BTW, the system(s) that I have to work on have no built-inCREATE not-ready...
IF not-ready THROW...CATCH.
- Peter Knaggs:
- This is absolutely essential if
REQUIREDis going to work. A library must be able to introduce it's own exceptions. The only problem I see here, is with regard to multilingual systems. The exception messages will be in the library author's language and not necessarily the language of the developer or user.