Table of Contents
1. stop
Terminates execution of the innermost stopped context.
1.3. Description
stop terminates execution of the innermost, dynamically enclosing instance of a stopped context, without regard to lexical relationship.
When stop executes:
1. Pops execution stack down to the stopped operator level
2. Pushes true on the operand stack
3. Resumes execution after the stopped operator
The operand and dictionary stacks are not affected - any objects pushed during stopped context execution remain.
1.5. Examples
Basic error handling
{
% ... code ...
errorCondition { stop } if
% ... more code ...
} stopped {
(Error occurred) print
} if
Graceful failure
{
riskyOperation
} stopped {
% stop was called
(Operation failed, using default) print
defaultValue
} if
Error propagation
/safeDiv {
dup 0 eq { pop stop } if
div
} def
{ 10 0 safeDiv } stopped {
(Division by zero avoided) print
0 % Default result
} if
1.6. Common Use Cases
1.6.1. Error Recovery
{
file readline not { stop } if
processLine
} stopped {
file closefile
(Error reading file) print
} if
1.7. Common Pitfalls
{ stop } exec % Prints error, executes quit
% (Only in top-level context)
| Doesn’t Clean Stacks - Objects remain on operand/dict stacks. |
{
1 2 3 % Push values
stop
} stopped pop
% Stack still contains: 1 2 3
| Use for Error Signaling - Preferred way to signal errors in custom operators. |
1.8. Error Conditions
| Error | Condition |
|---|---|
(none directly) |
If no enclosing stopped, interpreter handles it |
1.9. Implementation Notes
-
Unwinds execution stack only
-
Operand and dictionary stacks preserved
-
Very fast unwinding
-
Standard error mechanism