CATCH

Synopsis
CATCH tag instructionlist
Description

Command or operation that runs its instructionlist input and outputs whatever instructionlist outputs. If instructionlist runs a THROW instruction with a tag equal to the tag input (case-insensitive comparison), then the running of instructionlist is immediately terminated. In this case, CATCH outputs if a value input is given to THROW.

The tag input must be a word. If tag is the word ERROR, then any error condition that arises during the running of instructionlist has the effect of THROW "ERROR instead of printing an error message and returning to toplevel. In this case, CATCH does not output a value. Also, during the running of instructionlist, the variable ERRACT is temporarily unbound. (If there is an error while ERRACT has a value, that value is taken as an instruction list to be run after printing the error message. Typically the value of ERRACT, if any, is the list [PAUSE].)

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

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

MYPROGRAM1
Before throw
I'm back

SourceForge.net Logo