throw-restarts ( error restarts -- restart )
Factor handbook » The language » Exception handling » Restartable errors

Next:rethrow-restarts ( error restarts -- restart )


Vocabulary
continuations

Inputs
erroran object
restartsa sequence of { string object } pairs


Outputs
restartan object


Word description
Throws a restartable error using throw. The restarts parameter is a sequence of pairs where the first element in each pair is a human-readable description and the second is an arbitrary object. If the error reaches the top-level error handler, the user will be presented with the list of possible restarts, and upon invoking one, execution will continue after the call to throw-restarts with the object associated to the chosen restart on the stack.

Examples
Try invoking one of the two restarts which are offered after the below code throws an error:
: restart-test ( -- ) "Oops!" { { "One" 1 } { "Two" 2 } } throw-restarts "You restarted: " write . ; restart-test


See also
throw, rethrow, rethrow-restarts, throw-continue

Definition