An FAILURE condition happens when there is some severe error that a Function you call in a DLL/EXE, or (non-REXX) program that you launch, encounters as a result of doing its work. For example, if you try to launch some program that downloads a web page to a file, and that program can't be found, a FAILURE condition may occur.

Error/sub-error numbers

Whenever a FAILURE condition is raised, an error number, and possibly a sub-error number as well, is associated with that instance of the condition being raised. Each one of the numerous reasons for FAILURE being raised will produce a different combination of error/sub-error numbers. So, by checking the error/sub-error numbers, you can deduce exactly what went wrong in your script (ie, why the FAILURE condition was raised).

Your handler can use the CONDITION() built-in function's 'E' option to fetch the error and sub-error numbers associated with a given instance of that condition. CONDITION('E') will return the two numbers separated by a dot. For example, 80.81 will be returned for a FAILURE condition raised because an environment chose to raise this condition when you passed the environment a particular command. You'd have to consult the documentation with the environment to determine why it may have reacted this way to that particular command.

The error number can be thought of as a "general category number". And the sub-error number is a specific error within that category.

The following chart lists the error and sub-error numbers associated with the FAILURE condition, and what is the meaning of each combination of error/sub-error number.

65 Category: An untrapped FAILURE condition occurred in a child script. Reginald-only. CONDITION('D') reports the script name, exact error, and line number
80 Category: An error in an environment. Reginald-only
  80.1 An environment raised a FAILURE condition when it was passed a command
  80.3 An executable (EXE) launched by your script raised a FAILURE condition
  80.4 An exit handler raised a FAILURE condition when you tried to pass a command to an Environment
81 Category: An error in registering a function in a DLL/EXE. Reginald-only
  81.10 There is another function already registered with the same REXX name
  81.40 The DLL (in which the function is supposed to be located) can't be found
  81.50 The function name can't be found in the DLL

For errors, 81.40 and 81.50, the RXFUNCERRMSG() built-in may return a more informative error message than CONDITION('D').

A FAILURE condition can also be raised if you've issued an OPTIONS 'TRAP' instruction and are trapping FAILURE, and then you call some other script in which FAILURE is raised, but not trapped, in that child script. In this case, CONDITION('E') returns an error number of 65. (This is a Reginald-only feature). CONDITION('D') will return an error message that reports the name of the script in which FAILURE was raised, the line number where it occurred, and a reason why the condition was raised. Here is an example handler that would differentiate between FAILURE raised in your script versus another script that you called:

MyHandler:
   IF CONDITION('E') == '65' THEN DO
      PARSE VALUE CONDITION('D') WITH . '"' scriptname '"' . 'line ' linenum ': ' reason
      SAY 'FAILURE condition raised in "'|| scriptname ||'" at line' linenum ':' reason
   END
   ELSE DO
      SAY 'FAILURE condition raised at line' SIGL ':' CONDITION('D')
   END
   RETURN
Note: Reginald's CONDITION() function has an additional option. CONDITION('M') will present a pop-up message box containing the error message, the name of the script in which FAILURE was raised, the source line and line number upon which FAILURE was raised, and a Help button to bring up a help page for that error. This is preferable to trying to create your own message to present to the person running your script, since the online help may be supplied by the entity raising the condition.

RC variable

When you're passing a command to some environment, or telling the operating system (ie, 'CMD' environment) to launch some program, the special variable RC will be set to any error message or number returned by the program you launch, or by the environment to which you pass a command. This variable is set regardless of whether you have your own FAILURE handler, so you can always check the RC variable to see what error message or number a program or environment has returned. Often, the number 0 will be returned to indicate success, but this is just a guideline.

Note: The RC variable is created by the REXX interpreter, which assigns it a value when a condition is raised. You should never name your own variable RC, but may reference this variable.