catch and throw

Another mechanism that allows for code control is catch - throw. Have a look at the following example:

catch [    print "before throw"     throw "error"     print "after throw"]

This prints before throw and returns error. The throw word interrupts the code flow and goes back to the next higher level catch, returning the value given by throw catch must always be followed by a block [...] containing statements or a function call.

While case can only be used in a local block with all possible conditions specified, catch can be used when calling a function, that contains a throw, like this:

catch [ function-name arguments]

catch / throw works across function boundaries—a throw occurring in a nested function can be caught at a higher ...

Get Learn Red - Fundamentals of Red now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.