Propeller Manual

Table Of Contents
ABORT – Spin Language Reference
Page 48 · Propeller Manual v1.1
and more methods are returned from (via RETURN or by reaching the end of the method) the
call stack gets shorter. This is called “pushing” onto the stack and “popping” off of the stack,
respectively.
The RETURN command pops the most recent data off the call stack to facilitate returning to the
immediate caller; the one who directly called the method that just returned. The
ABORT
command, however, repetitively pops data off the call stack until it reaches a caller with an
Abort Trap (see below); returning to some higher-level caller that may have just been one
call, or many calls, up the nested chain of calls. Any return points along the way between an
aborting method and an abort trapping method are ignored and essentially terminated. In this
way,
ABORT allows code to back way out of a very deep and potentially complicated series of
logic to handle a serious issue at a high level.
Using ABORT
Any method can choose to issue an
ABORT command. It’s up to the higher-level code to
check for an abort status and handle it. This higher-level code can be either that which called
an aborting method directly, or via some other set of methods. To issue an
ABORT command,
use something like the following:
if <bad condition>
abort 'If bad condition detected, abort
—or—
if <bad condition>
abort <value> 'If bad condition detected, abort with value
...where <bad condition> is a condition that determines the method should abort and <value>
is a value to return upon aborting.
The Abort Trap (
\ )
To trap an
ABORT, the call to the method or method chain that could potentially abort must be
preceded with the Abort Trap symbol, a backslash (
T
\). For example, if a method named
MayAbort could possibly abort, or if it calls other methods that may abort, a calling method
could trap this with the following:
if \MayAbort 'Call MayAbort with abort trap
abort <value> 'Process abort