Introduces a parameter object in |current-clean-exception-handling|, which is set to #f by default. With clean exception handling switched off, exceptions happening during macro expansion trap into the repl at the point of the error. Signed-off-by: Christian Jaeger <christian@pflanze.mine.nu> --- Example: $ cat t.scm (define-macro (hello . body) (let ((v (error "an error"))) `(display (list "Hm: " ',v ',body)))) (hello "hua")
(include "t.scm") *** ERROR IN #<procedure #2>, "t.scm"@2.12 -- an error 1>
;; restore the old behaviour:
(current-clean-exception-handling #t) (include "t.scm") *** ERROR -- an error
lib/_repl.scm | 23 +++++++++++++++-------- 1 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/_repl.scm b/lib/_repl.scm index 3dc0aac..fe41fb6 100644 --- a/lib/_repl.scm +++ b/lib/_repl.scm @@ -2275,17 +2275,24 @@ (##exit)) + +(define current-clean-exception-handling (make-parameter #f)) + + (define-prim (##repl-within cont write-reason) (define (with-clean-exception-handling repl-context thunk) - (##with-exception-catcher - (lambda (exc) - (##continuation-graft ;; get rid of any useless continuation frames - (macro-repl-context-cont repl-context) - (lambda () - (release-ownership!) - (macro-raise exc)))) - thunk)) + (let ((old-handler (current-exception-handler))) + (with-exception-handler + (lambda (exc) + (if (current-clean-exception-handling) + (##continuation-graft ;; get rid of any useless continuation frames + (macro-repl-context-cont repl-context) + (lambda () + (release-ownership!) + (macro-raise exc))) + (old-handler exc))) + thunk))) (define (acquire-ownership!) (##repl-channel-acquire-ownership!)) -- 1.6.0.4