REBOL Document

Attempt - Function Summary


Tries to evaluate and returns result or NONE on error.


attempt value


value - The value argument.


The ATTEMPT function is a shortcut for the frequent case of:

    error? try [block]

The format for ATTEMPT is:

    attempt [block]

ATTEMPT is useful where you either do not care about the error result or you want to make simple types of decisions based on the error.

    attempt [make-dir %fred]

ATTEMPT returns the result of the block if an error did not occur. If an error did occur, a NONE is returned.

In the line:

    value: attempt [load %data]
    probe value

the value is set to NONE if the %data file cannot be loaded (e.g. it is missing or contains an error). This allows you to write conditional code such as:

    if not value: attempt [load %data] [print "Problem"]

Or code such as:

    value: any [attempt [load %data] [12 34]]
    probe value
    [12 34]


error? - Returns TRUE for error values.
try - Tries to DO a block and returns its value or an error.

<Back | Index | Next>

Copyright 2004 REBOL Technologies