Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
Version 1.9 Build 1556 |
|
The fail statement is used to indicate an error and provides an alternate way to return from a function. Typically a function returns by either executing the last statement of the function or an explicit return statement. There are two forms of fail you can use to return from a function:
fail expression
failTypically, the expression is a string describing the error condition, and when no expression is provided, the last fail value generated is used, if available.
An additional feature of fail values, i.e. the values produced and returned by fail statements, are automatically propagated. This is true at two different levels. When fail values are used in expressions (including function calls), the result is a fail value which is immediately generated without evaluation of the expression. Additionally if the fail value returned from a function call to an executing function, the result of the function which received the fail value will in turn be a fail value if the fail is not handled. A fail value is considered ``handled'' if its type has been checked, e.g. via type_name() or is_fail(). (See Chapter 9.1, page , for a complete description of fail.)