[plt-scheme] exception handler

From: David J. Neu (djneu at att.net)
Date: Tue Mar 22 12:37:05 EST 2005


I'm writing a cgi-bin script that opens a connection to a DBMS and I
wrote my own exception handling mechanism, which I've included below.

I wrap the opening of the dbms connection in a dynamic-wind to ensure
that it gets closed, however:

- if I include the (exit) at the end of html-exception-handler, the
  last thunk in the dynamic-wind isn't called when an exception occurs
  and the DBMS connection isn't closed

- if I exclude the (exit) at the end of html-exception-handler, the
  following message is written into the apache log file:
    [Tue Mar 22 12:16:51 2005] [error] [client] exception handler did not escape, referer: ...

So my question is, how should I escape from the exception handler?

Many thanks!


  (define exception-manager
    (lambda (e p)
      (let ((lstring-output-port (open-output-string)))
        (print-error-trace lstring-output-port e)
        (let ((lerror-trace (get-output-string lstring-output-port))
              (lerrorID (get-error-id)))
          ;; property: error-trace-filename
          (with-output-to-file "/tmp/error-trace.txt"
            (lambda ()
              (printf "~a~n" (exn-message e))
              (printf "~a" lerror-trace))
          ;; property: error-log-filename
          (with-output-to-file "/tmp/error-log.txt"
            (lambda ()
              (printf "ID: ~a~n" lerrorID)
              (printf "~a~n" (exn-message e))
              (printf "~a" lerror-trace)
              (printf "~n~n"))
          (p lerrorID)))))

;;; The procedure html-exception-handler passes the exception and the
;;; appropriate type of output formatting function to
;;; exception-manager
  (define html-exception-handler
    (lambda (aexn)
       ;; this procedure should be loaded as a property
       (lambda (aerrorID)
         (let ((lsxml
                `(html (head (title "Error"))
                       (body (@ (bgcolor "white"))
                              ,(format "Error: ~a" aerrorID))))))
           (output-html-from-sxml lsxml))))

Posted on the users mailing list.