Error Recovery

 Error Recovery

An execution error is an abnormal situation, related to the execution of a specific piece of a program. An error makes further execution impossible (or at least hazardous). "Overflow" and "division by zero" are examples of errors. Errors are identified by their unique error number and are always recognized by the robot. The occurrence of an error causes suspension of the normal program execution and the control is passed to an error handler. The concept of error handlers makes it possible to respond to and, possibly, recover from errors that arise during program execution. If further execution is not possible, the error handler can at least assure that the program is given a graceful abortion.

Error handlers

Any routine may include an error handler. The error handler is really a part of the routine, and the scope of any routine data also comprises the error handler of the routine. If an error occurs during the execution of the routine, control is transferred to its error handler.

The system variable ERRNO contains the error number of the (most recent) error and can be used by the error handler to identify that error. After any necessary actions have been taken, the error handler can:

When an error occurs in a routine that does not contain an error handler or when the end of the error handler is reached (ENDFUNC, ENDPROC or ENDTRAP), the system error handler is called. The system error handler just reports the error and stops the execution. In a chain of routine calls, each routine may have its own error handler. If an error occurs in a routine with an error handler, and the error is explicitly propagated using the RAISE instruction, the same error is raised again at the point of the call of the routine - the error is propagated. When the top of the call chain (the entry routine of the task) is reached without any error handler being found or when the end of any error handler is reached within the call chain, the system error handler is called. The system error handler just reports the error and stops the execution. Since a trap routine can only be called by the system (as a response to an interrupt), any propagation of an error from a trap routine is made to the system error handler.

Error recovery is not available for instructions in the backward handler. Such errors are always propagated to the system error handler.In addition to errors detected and raised by the robot, a program can explicitly raise errors using the RAISE instruction. This facility can be used to recover from complex situations. It can, for example, be used to escape from deeply-nested code positions.

Error numbers 1-90 may be used in the raise instruction. Explicitly-raised errors are treated exactly like errors raised by the system.Note that it is not possible to recover from or respond to errors that occur within an error clause. Such errors are always propagated to the system error handler.