Overview
The abort statement is a convenient shortcut to terminate the current transaction evaluation due to an error.
The syntax of the abort statement is:
abort <error_message> when [not] <expression>.
For example:
abort "I should not be negative" when I < 0.
or, equivalently:
abort "I should not be negative" when not I >= 0.
Abort During Initialization
There is a special syntactic form of the abort statement designed to work in combination (and only in combination) with variable initialization. In this case, rather than <expression>, the statement ends in is [not] <value>. This variation is most frequently used to eliminate NIL from an expression’s result set.
For example:
X = some_func some_argument abort "function returned NIL" when is NIL.
The type of
Xis inferred by the compiler as not nullable because the evaluator never allowsXto be equal toNILin this situation.
Provisional (Recoverable) Aborts
A plain abort terminates the transaction. A provisional abort —
written abort provisional <error> when <condition> — instead raises a
recoverable error that an enclosing handler can catch. If nothing
catches it, a provisional abort behaves like an ordinary abort.
abort provisional "Invalid platform type id." when !(_has platform_names id).
You catch a provisional abort with a when provisional abort block. The
block runs its body; if a provisional abort is raised inside the body,
the error is bound to the given name and execution continues after the
block. If no provisional abort is raised, the body runs to completion and
the bound name is NIL afterwards.
when provisional abort e {
// body that may raise a provisional abort
result -> compute value.
return result.
}
// reached only if the body raised a provisional abort; `e` holds the error
abort provisional "compute failed: " + e when e != NIL.
Together, abort provisional and when provisional abort give MUFL a
recoverable-error (raise / catch) mechanism, in contrast to the terminal
abort.