(dynamic-wind pre-thunk value-thunk post-thunk) applies its three thunk arguments in order. The value of a dynamic-wind expression is the value returned by value-thunk. The pre-thunk procedure is invoked before calling value-thunk and post-thunk is invoked after value-thunk returns. The special properties of dynamic-wind are manifest when control jumps into or out of value-thunk (either due to an exception or a continuation invocation): every time control jumps into value-thunk, pre-thunk is invoked, and every time control jumps out of value-thunk, post-thunk is invoked.
Example:
(let ([v (catch out
(dynamic-wind
(lambda () (display 'in) (newline))
(lambda ()
(display 'pre) (newline)
(display (call/cc out)) (newline)
#f)
(lambda () (display 'out) (newline))))])
(when v (v 'post)))
=>
in
pre
out
in
post
out