Table of Contents
1. stopped
Executes an object with error catching capability.
1.2. Stack Effects
| Level | Object |
|---|---|
0 |
|
| Level | Object |
|---|---|
(varies) |
Results from execution |
0 |
|
| Level | Object |
|---|---|
(varies) |
Partial results from execution |
0 |
|
1.3. Description
stopped executes any (typically a procedure).
-
If any runs to completion normally: returns
false -
If any terminates via
stop: returnstrue
Regardless of outcome, execution resumes at the next object after stopped.
This provides PostScript’s primary error-catching mechanism.
1.5. Examples
Basic error catching
{
% Code that might fail
10 0 div
} stopped {
% Error occurred
(Division error caught) print
} if
Normal completion
{
1 2 add
} stopped
% Returns: 3 false (normal completion)
Explicit stop
{
errorCondition { stop } if
normalCode
} stopped {
(Stopped explicitly) print
} if
1.6. Common Use Cases
1.6.1. Error Handler Pattern
{
% Main code
riskyOperation
} stopped {
% Error handler
handleerror
} if
1.7. Common Pitfalls
Catches All Errors - stopped catches ALL errors, including those you might not expect.
|
{
typoError % Undefined name
realCode
} stopped pop
% Error silently caught!
| Stack State - Operand and dict stacks not automatically cleaned on stop. |
{
1 2 3
stop
} stopped {
% Stack still contains: 1 2 3
clear % Must clean up manually
} if
| Standard Error Pattern - Default PostScript error handlers use this pattern. |
1.9. Implementation Notes
-
Creates new execution context
-
Execution stack level saved
-
Operand/dictionary stacks not affected by unwinding
-
PostScript’s exception handling mechanism
1.10. Standard Error Handler
The default error handler uses stopped:
% Simplified version
{
% User code
} stopped {
handleerror
} if