Operator Type:
Operator Scope of Action:
Operator Purpose:
Data Type Returned:
Operator First Added:
Operator in Current Baseline:
Operator Last Altered:
Function [other Function type actions]
Item [operators of similar scope]
Stream parsing [other Stream parsing operators]
success boolean
v9.1.0
Baseline
As at baseline
Syntax note: Operators without any defined mandatory arguments may omit their empty closing parentheses
fail()
fail
The fail operator makes an explicit declaration of a failure, and if invoked only ever returns false.
Often, in stream processing a failure occurs implicitly, for example because the end of the processed string is reached without finding the desired data. However, sometimes, there is a definite need to signal failure; for example, because the parsed data are invalid.
For example:
$MyString.try{
$MyString.skipTo(":").captureWord("TheWord");
if($TheWord.contains("None")) {
fail();
}
}
The above skips through $MyString to the first colon and then captures the next discrete word after the colon into $TheWord. The action fails if:
- if there is no colon
- if there is no word after the colon
- if $TheWord contains "None" as a case-sensitive exact full match or substring match.
See also—notes linking to here: