Propeller Manual

Table Of Contents
2: Spin Language Reference – ABORT
Propeller Manual v1.1 · Page 47
ABORT
Command: Exit from PUB/PRI method using abort status with optional return Value.
((PUB PRI))
ABORT Value
Returns: Either the current RESULT value, or Value if provided.
Value is an optional expression whose value is to be returned, with abort status, from
the
PUB or PRI method.
Explanation
ABORT is one of two commands (T ABORT and RETURN) that terminate a PUB or PRI method’s
execution.
ABORT causes a return from a T PUB or PRI method with abort status; meaning it pops the call
stack repeatedly until either the call stack is empty or it reaches a caller with an Abort Trap,
(
\ ), and delivers a value in the process.
ABORT is useful for cases where a method needs to terminate and indicate an abnormal or
elevated status to the immediate caller or one its previous callers. For example, an
application may be involved in a complicated chain of events where any one of those events
could lead to a different branch of the chain or a final action decision. It may be easier to
write that application using small, specialized methods that are called in a nested fashion,
each meant to deal with a specific sub-event in the chain. When one of the simple methods
determines a course of action, it can issue an abort that completely collapses the nested call
chain and prevents all the intermediate methods from continuing.
T
When
ABORT appears without the optional Value, it returns the current value of the T PUB/PRI’s
built-in
RESULT variable. If the Value field was entered, however, the PUB or PRI aborts and
returns that Value instead.
About the Call Stack
When methods are called simply by referring to them from other methods, there must be
some mechanism in place to store where to return to once the called method is completed.
This mechanism is a called a “stack” but we’ll use the term “call stack” here. It is simply
RAM memory used to store return addresses, return values, parameters and intermediate
results. As more and more methods are called, the call stack logically gets longer. As more