[plt-scheme] exception handler
Hi,
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 127.0.0.1] exception handler did not escape, referer: ...
So my question is, how should I escape from the exception handler?
Many thanks!
Cheers,
David
(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))
'truncate/replace)
;; 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"))
'append)
(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)
(exception-manager
aexn
;; this procedure should be loaded as a property
(lambda (aerrorID)
(let ((lsxml
`(html (head (title "Error"))
(body (@ (bgcolor "white"))
(center
,(format "Error: ~a" aerrorID))))))
(output-html-from-sxml lsxml))))
(exit)))