From 18b4292e4f3c56393ea6d6dd0249089c6a8e29c2 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Fri, 10 Feb 2017 23:13:42 +0000 Subject: [PATCH] Added with-handler --- scheme/base.sld | 15 +++++++++++++++ scripts/convert-doc-index.scm | 8 +++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/scheme/base.sld b/scheme/base.sld index 87ee67ff..0a398879 100644 --- a/scheme/base.sld +++ b/scheme/base.sld @@ -119,6 +119,7 @@ error raise raise-continuable + with-handler with-exception-handler Cyc-add-exception-handler Cyc-remove-exception-handler @@ -976,6 +977,20 @@ (define (raise-continuable obj) ((Cyc-current-exception-handler) (cons 'continuable (if (pair? obj) obj (list obj))))) + ;; A simpler exception handler based on the one from Bigloo: + ;; https://www-sop.inria.fr/indes/fp/Bigloo/doc/bigloo-17.html#g20889 + ;(define (with-handler handler body) + (define-syntax with-handler + (er-macro-transformer + (lambda (exp rename compare) + `(call/cc + (lambda (k) + (with-exception-handler + (lambda (obj) + (,(cadr exp) obj) + (k #t)) + (lambda () + ,@(cddr exp)))))))) (define (with-exception-handler handler thunk) (let ((result #f) (my-handler diff --git a/scripts/convert-doc-index.scm b/scripts/convert-doc-index.scm index 500be569..20681295 100644 --- a/scripts/convert-doc-index.scm +++ b/scripts/convert-doc-index.scm @@ -46,7 +46,13 @@ (define (loop) (let ((line (read-line))) (when (not (eof-object? line)) - (call/cc + (with-handler + (lambda (obj) + (display `(Error processing line ,line details ,obj))) + (display (convert-line line)) + (newline)) + + #;(call/cc (lambda (k) (with-exception-handler (lambda (obj)