Operator Type:
Operator Scope of Action:
Operator Purpose:
Operator First Added:
Operator Last Altered:
Function [other Function type actions]
Item [operators of similar scope]
Stream parsing [other Stream parsing operators]
Baseline
As at baseline
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.