Version 0 of Script termination: results and control

Updated 2013-12-09 11:24:27 by PeterLewerin

PL: I'm just starting up this page. It's intended to explain the low-level details of terminating scripts, as regards termination categories (ok, error, return, break, continue), result values (valid data vs error messages), and handling exceptional termination.

proc caller {} {
    set result [callee]
}
control { script } ;# -> result of control might be result of script
commandA ;# -> resultA
commandB ;# -> resultB
commandC ;# -> resultC

As long as none of these commands are terminating commands and no error occurs, the evaluation of this script goes like this: commandA is invoked, its side-effects (if any) happen, and its result (resultA) is produced and discarded. The same thing happens to commandB and commandC, but as the script terminates after commandC, resultC isn't discarded: instead it becomes the result of the evaluation of the script, and gets passed back to the caller. This is a normal termination, where the result is valid data.

Now, if commandB is a terminating command, evaluation goes differently. Commands commandA and commandB are invoked and their side-effects happen, but commandC doesn't get invoked at all and its side-effect doesn't happen. The result of commandB becomes the result of the evaluation of the script. This can still be a normal termination, but it can also be some kind of exceptional termination. In the latter case, resultB isn't valid data but an error message.

If an error occurs during execution of commandB, the situation is similar to the last paragraph. Commands commandA and commandB are invoked, but only commandA is completed successfully. The side-effect of commandB may or may not happen, or happen partially. The normal result of commandB is replaced by an error message, which becomes the result of the evaluation of the script. This is exceptional termination.

In the case of normal termination, control is passed back to the caller. In the case of exceptional termination, control is passed to a handler. The handler needs to know which kind of termination happened, so it can know whether to treat the result value as valid data or as an error message.

(I'll be back soon -- PL)