THROW

Synopsis
THROW tag
(THROW tag value)
(THROW "ERROR errortext)
(THROW "ERROR 4 badvalue)
Description

Ends the running of a CATCH instruction's instructionlist input. THROW must be used within the scope of a CATCH instruction that has a tag equal to tag. If THROW is given a value input, then CATCH outputs value. If THROW is not given a value input, then the corresponding CATCH does not output a value.

The tag input must be a word.

THROW "SYSTEM causes FMSLogo to immediately exit.

THROW "TOPLEVEL terminates all running procedures and interactive pauses, and returns control to the toplevel instruction prompt. This has the same effect as pressing the Halt Button.

THROW "ERROR can be used to generate an error condition. If the error is not caught, it prints a message (Throw "Error) with the usual indication of where the error (in this case the THROW) occurred. If tag equals "ERROR and an errortext input is given, then errortext is used as the text of the error message instead of the standard message. In this case, the location indicated for the error is not the location of the THROW, but the location where the procedure containing the THROW was invoked. This allows user-defined procedures to generate error messages as if they were primitives. If tag equals "ERROR and the second input is 4 (the error code for bad input) and a third input exists, then a "bad input" error is thrown and the third input is used as the value of the bad input.

Note that when THROW "ERROR is used, the corresponding CATCH "ERROR, if any, does not output a value because the second input to THROW is treated as an error message, not an output.

Example
TO MYPROGRAM2
  PRINT [Before throw]
  (THROW "tag1 [We need to get back])
  PRINT [We never get here because we THROW back]
END

TO MYPROGRAM1
  SHOW CATCH "tag1 [MYPROGRAM2]
  PRINT [I'm back]
END

MYPROGRAM1
Before throw
[We need to get back]
I'm back

SourceForge.net Logo