rexx has the ability to also work on error handling as in other programming languages.
the following are some of the various error conditions that are seen in rexx.
error − this even is raised whenever a command which is sent to the operating system results in an error.
failure − this even is raised whenever a command which is sent to the operating system results in a failure.
halt − this is normally raised whenever an operation is dependent on another operation. an example is if an i/o operation is being halted for any reason.
novalue − this event is raised when a value has not been assigned to a variable.
notready − this is raised by any i/o device which is not ready to accept any operation.
syntax − this event is raised if there is any syntax error in the code.
lostdigits − this event is raised when an arithmetic operation results in a loss of digits during the operation.
trapping errors
errors are trapped with the help of the signal command. let’s take a look at the syntax and an example of this.
syntax
signal on [errorcondition]
where,
errorcondition − this is the error condition which is given above.
example
let’s take a look at an example on this.
/* main program */ signal on error signal on failure signal on syntax signal on novalue beep(1) signal off error signal off failure signal off syntax signal off novalue exit 0 error: failure: syntax: novalue: say 'an error has occured'
in the above example, we first turn the error signals on. we then add a statement which will result in an error. we then have the error trap label to display a custom error message.
the output of the above program will be as shown below.
an error has occurred.
an example of error codes is shown in the following program.
/* main program */ signal on error signal on failure signal on syntax signal on novalue beep(1) exit 0 error: failure: syntax: novalue: say 'an error has occured' say rc say signal
the output of the above program will be as shown below.
an error has occured 40 6