From cc75d7b44c5be7a3a9d1e40f419f0c2e375404a8 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Thu, 19 Mar 2015 13:20:44 -0400 Subject: [PATCH] Added (with-exception-handler) --- trans.scm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/trans.scm b/trans.scm index 9b3f3a42..58bf5bf2 100644 --- a/trans.scm +++ b/trans.scm @@ -69,8 +69,19 @@ (foldr (lambda (x y) (cons (func x) y)) '() lst)) (define (not x) (if x #f #t)) (define (reverse lst) (foldl cons '() lst)) -; (define (with-exception-handler handler thunk) -; + (define (with-exception-handler handler thunk) + (let ((my-handler + (lambda (obj) + ;; Unregister this handler since it is no longer needed + (Cyc-remove-exception-handler) + (handler obj) ;; Actual handler + (error "exception handler returned")))) + ;; TODO: cond-expand below, since it uses Cyc functions? + ;; probably no need since this is part of internal lib + (Cyc-add-exception-handler my-handler) + (thunk) + ;; Only reached if no ex raised + (Cyc-remove-exception-handler))) )) ;; Built-in macros