09.12.2012 Views

Basic Characteristics RAPID

Basic Characteristics RAPID

Basic Characteristics RAPID

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Basic</strong> <strong>Characteristics</strong> <strong>RAPID</strong> Error Recovery<br />

8 Error Recovery<br />

An execution error is an abnormal situation, related to the execution of a specific piece<br />

of a program. An error makes further execution impossible (or at least hazardous).<br />

“Overflow” and “division by zero” are examples of errors. Errors are identified by their<br />

unique error number and are always recognized by the robot. The occurrence of an<br />

error causes suspension of the normal program execution and the control is passed to<br />

an error handler. The concept of error handlers makes it possible to respond to and,<br />

possibly, recover from errors that arise during program execution. If further execution<br />

is not possible, the error handler can at least assure that the program is given a graceful<br />

abortion.<br />

8.1 Error handlers<br />

Any routine may include an error handler. The error handler is really a part of the routine,<br />

and the scope of any routine data also comprises the error handler of the routine.<br />

If an error occurs during the execution of the routine, control is transferred to its error<br />

handler.<br />

Example: FUNC num safediv( num x, num y)<br />

RETURN x / y;<br />

ERROR<br />

IF ERRNO = ERR_DIVZERO THEN<br />

TPWrite "The number cannot be equal 0";<br />

RETURN x;<br />

ENDIF<br />

!All other errors are propagated RAISE;<br />

ENDFUNC<br />

The system variable ERRNO contains the error number of the (most recent) error and<br />

can be used by the error handler to identify that error. After any necessary actions have<br />

been taken, the error handler can:<br />

- Resume execution, starting with the instruction in which the error occurred.<br />

This is done using the RETRY instruction. If this instruction causes the same<br />

error again, up to five error recoveries will take place; after that execution will<br />

stop.<br />

- Resume execution, starting with the instruction following the instruction in<br />

which the error occurred. This is done using the TRYNEXT instruction.<br />

- Return control to the caller of the routine using the RETURN instruction. If the<br />

routine is a function, the RETURN instruction must specify an appropriate<br />

return value.<br />

- Propagate the error to the caller of the routine using the RAISE instruction.<br />

An error handler should normally end with RAISE or EXIT, in order to take care of<br />

errors that cannot be handled.<br />

In a chain of routine calls, each routine may have its own error handler. If an error<br />

<strong>RAPID</strong> Reference Manual 5-33

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!