-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp1.scm
45 lines (32 loc) · 868 Bytes
/
app1.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
;;; File: app1.scm
;;;----------------------------------------------------------------------------
(declare (standard-bindings) (extended-bindings) (not safe))
(define (exception->string exc)
(let ((port (##open-string)))
(##display-exception exc port)
(##newline port)
(##get-output-string port)))
(define (handle exc)
(println (exception->string exc)))
(println "--------------------------------")
(with-exception-catcher
handle
(lambda ()
(+ 1 'foobar)))
(println "--------------------------------")
(##current-exception-handler handle)
(+ 2 'allo)
;; output:
;;
;; --------------------------------
;; (Argument 2) NUMBER expected
;; (+ 1 'foobar)
;;
;;
;; --------------------------------
;; (Argument 2) NUMBER expected
;; (+ 2 'allo)
;;
;;
(println (trap-eval-string "(+ 11 22)"))
(println (trap-eval-string "(bar 11 22)"))