CATCH

Syntax

CATCH word instructionlist

Explanation

CATCH runs the intructions in its second input. If Logo encounters a THROW statement with the same word argument, control returns to CATCH.

There are two special uses of CATCH. If the first input to CATCH is TRUE, any THROW statement will be caught. Also, CATCH "ERROR catches an error that would otherwise print a Logo message and return to toplevel. In this case, the built-in variable ERROR contains a hint about which error occured.

Examples

The following example asks you to type a name. If you type a number instead, the program prints a message and continues.

TO NAMIT


 * CATCH "NOTNAME [NAMIT1 STOP]


 * NAMIT

END

TO NAMIT1


 * PRINT [PLEASE TYPE A NAME]


 * MAKE "NAME READ


 * IF NUMBER? :NAME \


 * [PRINT [THAT'S A NUMBER, NOT A NAME] THROW "NOTNAME]


 * PRINT (SE :NAME [IS A GOOD NAME])

END

? NAMIT

PLEASE TYPE A NAME

? KURT

KURT IS A GOOD NAME

PLEASE TYPE A NAME

? 5

THAT'S A NUMBER NOT A NAME

?

Type Control-G to return to toplevel.

In the following example, AVOID.INTERRUPTIONS runs the commands you type. If an error occurs, Logo prints

THAT'S NOT A LOGO COMMAND

and continues executing the procedure instead of printing the usual Logo message and terminating the procedure by returning to toplevel.

TO AVOID.INTERRUPTIONS


 * CATCH "ERROR [AVOID.INTERRUPTIONS1]


 * PRINT [THAT'S NOT A LOGO COMMAND]


 * AVOID.INTERRUPTIONS

END

TO AVOID.INTERRUPTIONS1


 * RUN READLIST


 * AVOID.INTERRUPTIONS1

END

? AVOID.INTERRUPTIONS

? PRINT [THIS IS RIGHT]

THIS IS RIGHT

? PRINT THIS IS RIGHT

THAT'S NOT A LOGO COMMAND

?

Type TOPLEVEL or Control-G to return to toplevel.