Evlan
Error Handling
Last updated at 2005/04/23 14:49:38 PDT by Temporal

Since Evlan currently has no type system, many types of programming errors which would normally be caught by such a system must instead be detected and reported at runtime. Specifically, the following types of errors fall in this category:

  • Trying to apply a value which is not a function.

  • Providing the wrong number of parameters to a function (arity mismatch).

  • Trying to access a member field of a value which is not an object.

  • Trying to access a member field of an object which has no member by that name.

  • Trying to access an element of an array outside of that array's bounds (i.e. with an index which is less than zero or greater than or equal to the size of the array).

  • Providing a non-boolean value as the conditional to an if/then/else expression.

  • Providing a parameter of an incorrect type to a built-in operator or function (i.e. trying to add boolean values or trying to multiply by an object).

When one of these errors occurs during the evaluation of an expression, the result of the expression is an error value. If that error value is used as an input to another operation, the result of that operation will be the same error value. Thus, errors propagate up to the original caller as they are repeatedly used as inputs to operations.

Note, however, that if the result of an operation does not depend in any way on the value of one of its inputs, then the operation can succeed even if that input is an error. Most notably, if the boolean "and" operator is applied to an error value, but the other parameter is false (regardless of the order), the result will be false. Similarly, a boolean "or" will return true if either parameter is true, even if the other parameter is an error. Also, a function which simply does not use one of its parameters will not necessarily return an error when the caller passes an error for that parameter.

Generally, you are not expected to detect when an expression evaluates to an error. Just go ahead and use the value. The error will then propagate to the caller, and eventually out to the interpreter prompt, where it will be reported, allowing the user to find and fix the problem. You generally should not write code which intentionally produces error values then attempts to detect them.

That said, if you do want to detect whether or not a value is an error, you can call Object.isError(), which returns true if its parameter is an error and false otherwise.

evlan.org © Copyright 2003-2005 Kenton Varda
Powered by Io Community Manager, Evlan, and FreeBSD