Continuations and freeing the stack

For an error recovery system that supports resume, I was thinking of packing the current continuation in the exception object. However, that raises an issue with freeing the resources: even though the program pointer escaped the context of the error, there is still a way to return there with "resume".

For example:

def foo(x) = 3 + (50 / x)
...
foo 0
catch
   e : DivisionByZero   e.resume 42   #the answer is 42
 | other                throw other

How do you normally deal with continuations that are returned from the current context?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

You use heap allocated stack

You use heap allocated stack frames and garbage collection instead of a plain old push/pop stack.

Resumable exceptions are very easy

As has been discussed on LtU, resumable exceptions are quite easy to implement. The key observation is that the continuation to resume is a `one-shot continuation', which is effectively implementable without any need to capture it. Please see the above LtU thread for details, and, perhaps, sample implementation in OCaml.