[r6rs-discuss] [Formal] returning exception handlers easily trigger infinite loops

Robby Findler robby at cs.uchicago.edu
Sun Jan 28 09:56:32 EST 2007

This message is a formal comment which was submitted to formal-comment at r6rs.org, following the requirements described at: http://www.r6rs.org/process.html
# type of issue: defect
# priority: as you decide
# R6RS component: Exceptions

# version of the report: 5.92
# one-sentence summary of the issue:
  returning exception handlers easily trigger infinite loops

# full description of the issue:

As I understand the current informal spec (with help from Mike) and as
is shown in the operational semantics, exception handlers that return
to a `raise' very easily get into infinite loops. (Indeed, without
effects or dispatching on the exception itself, it seems impossible to
avoid an infinite loop when a handler returns.)

For example these programs:

  (with-exception-handler (lambda (x) x) (lambda () (raise 1)))
  (with-exception-handler (lambda (x) x) (lambda () (car '())))

both result in infinite loops. (Try it out! :)

I believe that there is a simple fix to this, namely to make the
implicit raise (the one that gets triggered when the handler returns)
be in the same context as call to the handler. That is, in the handler
context that does not contain the handler that just returned.

>From the operational semantics point of view, it means changing the
begin expression in the 6xraise rule from this:

(begin (handlers v_1 ... (v_2 v_3)) (raise (condition "handler returned")))

to this:

(handlers v_1 ... (begin (v_2 v_3) (raise (condition "handler returned"))))


More information about the r6rs-discuss mailing list