I have an ATMega328p running AmForth 6.1.
While interactively debugging, I accidentally called an undefined word, resulting in AmForth throwing a -13
exception (undefined word
).
After the exception is thrown, AmForth acts strange. Calls to pre-defined words such as words
, or simple operations like 1 1 +
fail.
The only solution I've found thusfar is to re-flash the chip, which is obviously less than ideal.
Am I not handling errors properly? Coming from a GForth background, I am used to just contining operation on exceptions. It seems like AmForth does not operate this way.
How do I get AmForth to behave correctly after calling an undefined word?
Here's an example of using CATCH
and THROW
:
\ Throw an exception.
: check 42 throw ;
\ Call check, and catch any exception.
' check catch .
\ Should print 42.
I mentioned QUIT
because it's the default Forth interpreter, and in the AmForth source code, it looks like it should catch exceptions. Maybe you're using another version of AmForth, or you're not interacting with the standard text interpreter.
QUIT
just enters the Forth text interpreter. It may seem a peculiar name, but it makes sense if you call it from a word. No matter how deep the return stack is, QUIT
empties it and goes to interactive mode. It keeps the data stack, however.
: foo 1 2 3 quit ;
: bar foo ;
bar .s \ Should print 1 2 3.