Take Over Error Handling

DESCRIPTION:
Causes the occurrence of errors to restart the function that called restart.

USAGE:
restart(on=T)

OPTIONAL ARGUMENTS:
on:
if TRUE, cause errors to recall the function from which restart was called. If FALSE, error control is returned to S-PLUS (but see below).

SIDE EFFECTS:
after it is called, and until a return from the function evaluation that contained the call to restart, all errors and interrupts, with one exception, will not get the user back to the S-PLUS prompt level. Instead, the function that called restart will be recalled, but with its local frame in the state that obtained when the error occurred. (restart will have been canceled at this point, but typically the restarted function will then call restart again.)

DETAILS:
The quit signal (usually typed as control-backslash) will cancel unconditionally the restart and return the user to S-PLUS prompt level. Keep in mind that a second quit signal will exit S-PLUS entirely. (The quit signal has nothing to do with the S-PLUS function q.)

This is a function to be used only by the adept and strong at heart. Use of restart can be dangerous to your health and social standing. In particular, if the function calling restart has an error, an infinite loop of errors can easily result; hence the use of quit as a loop-hole.


WARNING:
ALWAYS make sure that the calling function is bug-free before installing a call to restart.

SEE ALSO:
browser , debugger , dump.calls , trace , .Program .

EXAMPLES:
amp;# prompt for expressions & evaluate them
pause <- function() {
        restart(T)
        cat("Enter expressions, q to quit from pause\n")
        repeat {
                e <- parse(prompt = "<P> ")
                if(is.name(e[[1]]) && e[[1]]=="q")
                   return()
                print(eval(e, local = sys.parent(1)))
        }
}
amp;# look at browser for another example