Program termination: Difference between revisions

→‎{{header|Wren}}: Added a third option to the preamble.
(Added Wren)
(→‎{{header|Wren}}: Added a third option to the preamble.)
Line 1,584:
A main fiber is created automatically when a script begins and further fibers can then be created as required.
 
To terminate a script from within a conditional, twothree options are available: Fiber.suspend, or Fiber.abort or the ''return'' statement.
 
Fiber.suspend pauses the current fiber, stops the interpreter and returns control to the host application though the fiber can be resumed later. If called from a Wren CLI script, control simply returns to the operating system as there is no host application as such and therefore no possibility of resumption.
 
Fiber.abort generally means that a runtime error has occurred though you can still call it if you wish with either no error or a manufactured error. After aborting the current fiber, if the error is not caught, all invoking fibers up to the main one are also aborted and the VM is exited with an appropriate error message and stack trace. As far as I know, no special cleanup is provided by the VM itself.
 
In module level code (i.e. code which is outside a function or method), the ''return'' statement appears to terminate the script without error though this behavior is undocumented and so should be used with caution.
 
The following example illustrates the use of Fiber.suspend in a Wren CLI script.
9,476

edits