#!/usr/bin/env -S guile --no-auto-compile -e main -s !# (use-modules (ice-9 control)) (define* (test #:key (unwind? #f)) (let/ec return (with-exception-handler (let ((nested #f)) (lambda (c-level-1) (if nested (begin (format #t "level 1 handler got called recursively~%") 'level-1-handler-nested) (begin (set! nested #t) (with-exception-handler (lambda (c-level-2) (begin (format #t "level 2 handler got error ~A~%" c-level-2) (format #t "level 2 handler is returning~%") (return 'level-2-handler))) (lambda () (format #t "level 1 handler~%") (error "let's signal a nested error...") (format #t "level 1 handler is returning~%") (return 'level-1-handler)) #:unwind? unwind?))))) (lambda () (error "let's signal an error...") 'thunk) #:unwind? unwind?))) (define (main cmd) (unsetenv "COLUMNS") (format #t "~%~%*** calling with unwind~%") (format #t "return value is: ~A~%" (test #:unwind? #t)) (format #t "~%~%*** calling without unwind~%") (format #t "return value is: ~A~%" (test #:unwind? #f))) #| $ guile --version guile (GNU Guile) 3.0.9 $ guile --no-auto-compile -e main -s ~/workspace/guile/test.scm *** calling with unwind level 1 handler level 2 handler got error #<&compound-exception components: (#<&error> #<&origin origin: #f> #<&message message: "~A"> #<&irritants irritants: ("let's signal a nested error...")> #<&exception-with-kind-and-args kind: misc-error args: (#f "~A" ("let's signal a nested error...") #f)>)> level 2 handler is returning return value is: level-2-handler *** calling without unwind level 1 handler Backtrace: In ice-9/boot-9.scm: 1752:10 12 (with-exception-handler _ _ #:unwind? _ # _) In unknown file: 11 (apply-smob/0 #) In ice-9/boot-9.scm: 724:2 10 (call-with-prompt ("prompt") # …) In ice-9/eval.scm: 619:8 9 (_ #(#(#))) 163:9 8 (_ #(#(#) ("/ho…"))) In ice-9/boot-9.scm: 724:2 7 (call-with-prompt (let/ec) # …) 1752:10 6 (with-exception-handler _ _ #:unwind? _ # _) In ice-9/eval.scm: 619:8 5 (_ #(#(#))) In ice-9/boot-9.scm: 2007:7 4 (error _ . _) 1685:16 3 (raise-exception _ #:continuable? _) 1752:10 2 (with-exception-handler _ _ #:unwind? _ # _) In ice-9/eval.scm: 619:8 1 (_ #(#(# #))) In ice-9/boot-9.scm: 2007:7 0 (error _ . _) ice-9/boot-9.scm:2007:7: In procedure error: let's signal a nested error... $ |# #| $ /gnu/store/xm08cp3fz3jxq3zddg9cvj59idy3ri8b-guile-3.0.99-git/bin/guile --no-auto-compile -e main -s ~/workspace/guile/test.scm *** calling with unwind level 1 handler level 2 handler got error #<&compound-exception components: (#<&error> #<&origin origin: #f> #<&message message: "~A"> #<&irritants irritants: ("let's signal a nested error...")> #<&exception-with-kind-and-args kind: misc-error args: (#f "~A" ("let's signal a nested error...") #f)>)> level 2 handler is returning return value is: level-2-handler *** calling without unwind level 1 handler level 2 handler got error #<&compound-exception components: (#<&error> #<&origin origin: #f> #<&message message: "~A"> #<&irritants irritants: ("let's signal a nested error...")> #<&exception-with-kind-and-args kind: misc-error args: (#f "~A" ("let's signal a nested error...") #f)>)> level 2 handler is returning return value is: level-2-handler $ |#