1. stop

Terminates execution of the innermost stopped context.

1.1. Syntax

– stop → –

1.2. Stack Effects

Table 1. Before/After
Level Object

(varies)

Unwinds to 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.4. PostScript Level

Level 1 and later

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.6.2. Validation

/validate {
  conditions {
    not { stop } if
  } forall
} def

{ validate processData } stopped {
  (Validation failed) print
} if

1.6.3. Safe Execution

/trySeveral {
  {
    method1 exit
  } stopped pop
  {
    method2 exit
  } stopped pop
  {
    method3 exit
  } stopped pop
  % All failed
  fallbackMethod
} def

1.7. Common Pitfalls

Requires stopped Context - Without enclosing stopped, prints error and calls quit.
{ 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

1.10. Pattern: Custom Error Handling

/myOperator {
  % Validate inputs
  validationFailed { stop } if

  % Perform operation
  { riskyCode } stopped { stop } if

  % Return results
} def

% Usage
{ myOperator } stopped {
  % Handle any error
  handleError
} if

1.11. See Also

  • stopped - Create stopped context

  • exit - Exit loop

  • quit - Terminate interpreter

  • Error Handling (to be documented)


Back to top

Copyright © 2025 Ribose. PostScript is a trademark of Adobe. Distributed under the MIT License.