REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 3-Aug-2010 Edit History  

REBOL 3 Functions: catch

catch  block  /name  word  /quit

Catches a throw from a block and returns its value.


block [block!] - Block to evaluate


/name - Catches a named throw

word [word! block!] - One or more names

/quit - Special catch for QUIT native

See also:

throw   do   try  


catch and throw go together. They provide a way to exit from a block without evaluating the rest of the block. To use it, provide catch with a block to evaluate. If within that block a throw is evaluated, it will return from the catch at that point.

The result of the catch will be whatever was passed as the argument to the throw.

write %file.txt "i am a happy little file with no real purpose"
print catch [
    if exists? %file.txt [throw "Doc found"]
    "Doc not found"
Doc not found

When using multiple catch functions, provide them with a name using the /name refinement to identify which one will catch which throw.

Editor note: Example with /name

Editor note: Example of using catch in a function spec.

  TOC < Back Next > - WIP Wiki Feedback Admin