Skip to content

Instantly share code, notes, and snippets.

@taw10
Created May 21, 2022 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taw10/a7cc755c6e8c45804c9dedfd609d4eae to your computer and use it in GitHub Desktop.
Save taw10/a7cc755c6e8c45804c9dedfd609d4eae to your computer and use it in GitHub Desktop.
Exception handling with Guile 3.0.7
(use-modules (ice-9 threads)
(ice-9 exceptions)
(ice-9 control))
(define (do-test)
(raise-exception
(make-exception
(make-exception-with-message "Test exception")
(make-exception-with-irritants (list 1 2 3 4 5)))))
(define (call-with-backtrace thunk)
(let/ec cancel
(start-stack 'stack-with-backtrace
(with-exception-handler
(lambda (exn)
(display "Error occurred\n")
(backtrace)
(cancel #f))
thunk))))
(define (exception-test)
(call-with-backtrace
(lambda ()
(sleep 1)
(do-test))))
(exception-test)
Output:
[23:06] ~ guile exception-test.scm
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the --no-auto-compile argument to disable.
;;; compiling /home/taw/exception-test.scm
;;; compiled /home/taw/.cache/guile/ccache/3.0-LE-8-4.5/home/taw/exception-test.scm.go
Error occurred
Backtrace:
Backtrace:
In ice-9/boot-9.scm:
1752:10 7 (with-exception-handler _ _ #:unwind? _ # _)
1685:16 6 (raise-exception _ #:continuable? _)
In /home/taw/exception-test.scm:
18:27 5 (_ _)
In unknown file:
4 (backtrace #<undefined>)
In system/repl/debug.scm:
148:36 3 (print-frames #(#<frame 7f0623f102d0 backtrace> #<f…> …) …)
72:20 2 (_)
In ice-9/boot-9.scm:
1747:15 1 (with-exception-handler #<procedure 7f0623e1a630 at ic…> …)
In system/repl/debug.scm:
72:40 0 (_)
system/repl/debug.scm:72:40: In procedure string->number: Wrong type argument in position 1 (expecting string): #f
[23:07] ~ $
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment