[attrname := ] FAIL [ ( errormessage | errorcode ) ] ;
[attrname := ] FAIL( errorcode , errormessage ) ;
[attrname := ] FAIL( datatype [, [ errorcode ] [, errormessage ] ] ) ;
attrname | Optional. The action name, which turns the action into an attribute definition, therefore not executed until the attrname is used as an action. |
errormessage | Optional. A string constant containing the message to display. |
errorcode | Optional. An integer constant containing the error number to display. |
datatype | The value type, name of a RECORD structure, DATASET, or DICTIONARY to emulate. |
The FAIL action immediately halts processing on the workunit and displays the errorcode and/or errormessage. The third form is available for use in contexts where a value type or dataset is required. FAIL may not be used in an expression context (such as within a TRANSFORM)--use the ERROR function for those situations.
Example:
MyRec := RECORD
STRING50 Value1;
UNSIGNED Value2;
END;
ds := DATASET([{'C',1},{'C',2},{'C',3},
{'C',4},{'C',5},{'X',1},{'A',1}],MyRec);
MyRec FailTransform := TRANSFORM
self.value1 := FAILMESSAGE[1..17];
self.value2 := FAILCODE
END;
limited1 := LIMIT(ds, 2);
limited2 := LIMIT(ds, 3);
limited3 := LIMIT(ds, 4);
recovered1 := CATCH(limited1, SKIP);
recovered2 := CATCH(limited2, ONFAIL(FailTransform));
recovered3 := CATCH(CATCH(limited3, FAIL(1, 'Failed, sorry')), ONFAIL(FailTransform));
OUTPUT(recovered1); //empty recordset
OUTPUT(recovered2); //
OUTPUT(recovered3); //