>> x = [3, 5,] Error: unexpected closing bracket
A program may have passed the phase of parsing, but during execution may still run into an abnormal event that must cause the program to abort. Such an error is called a run-time error or exception. Typical run-time errors include out-of-bound array indices and function domain errors. For example
>> s = function x -> y y = x[1] + x[2]; end >> s(3) Error: index out of boundWhen the above piece of code is processed, the interpreter doesn't find any syntax error. The expression s(3) appears to be ok since it's very hard for the interpreter to note the fact that function s expects a matrix with length at least 2. The detection and handling of such an error is delayed untill run-time.
A function may specify a domain, in which case, the interpreter may check domain error during parsing time and detect such errors. In general it's difficult to tell what kind of errors are caught at which time unless user programs are meticulously designed to ensure that all invalid argument values are caught by the interpreter and not passed to the function.
When an error occurs during the execution of a program, the default action of the interpreter is to display some error message and information about where the error occurs, and then execution of the commands and functions is terminated. The interpreter returns to the interactive level and waits for new commands.
Alternatively, a user program may try to `catch' and handle an error, and continue to do other tasks from the point where the error is caught. This way the program flow is not interrupted, and the interpreter is not brought all the way down to the user interactive level.
oz 2009-12-22