I define a custom exception:

    (define-struct (my-exception exn:fail) ())

    (define (my-error fmt . args)
      (let ((msg (apply format (cons fmt args))))
        (raise (my-exception msg (current-continuation-marks)))))

The plan is that I can throw this within a servlet, and then catch it, and produce a 5xx response, within a with-handlers clause wrapping the dispatcher passed to serve/servlet. However this doesn't always work as I expect it to. The exception is thrown inside the 'output' procedure that's provided as the last argument to the 'response' constructor (I belatedly realise this is probably a bad idea).

Sometimes, when the custom exception is thrown, that exception appears, not prettyprinted via the handler that I have defined, but printed on stderr via the default exception output formatter:

My exception-message ...

Looking at that place in the file, I see

(define (output-response-body/chunked conn bresp)
  (with-handlers ([exn:fail? (lambda (e)
                               (kill-thread to-chunker-t))])

...which causes the servlet to (effectively) hang, so that the client sits around waiting for output that isn't going to come.

Exactly the same thing happens if I avoid wrapping the dispatcher, and instead provide a #:servlet-responder procedure as a keyword argument to serve/servlet.

Now, in tracking this down I can see that I have a wrong design here: the servlet has started producing output before the exception is thrown, so it's at this point really too late for me to be throwing errors and producing custom 5xx error pages.

But (a) what should I be doing? And (b) since that exception is caught in this with-handlers clause, what is it that's producing the (default) exception output message? And (c) should I expect the client just to hang here?

I'm guessing that an answer to (a) is 'avoid throwing exceptions inside 'output', but given that that will sometimes happen, is the output-response-body/chunked procedure doing the right thing here? Am I missing something?

Best wishes,


Norman Gray  :
SUPA School of Physics and Astronomy, University of Glasgow, UK

You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
To view this discussion on the web visit

Reply via email to