-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathexceptions.scm
59 lines (53 loc) · 1.28 KB
/
exceptions.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
; no exception
(call-with-current-continuation
(lambda (k)
(with-exception-handler
(lambda (x)
(display "condition: ")
(write x)
(newline)
(k 'exception))
(lambda ()
(print (+ 1 17))))))
; exception
(call-with-current-continuation
(lambda (k)
(with-exception-handler
(lambda (x)
(display "condition: ")
(write x)
(newline)
(k 'exception))
(lambda ()
(print (+ 1 (raise 'an-error)))))))
; exception without call/cc
(with-exception-handler
(lambda (x)
(display "something went wrong\n"))
(lambda ()
(print (+ 1 (raise 'an-error)))))
; exception from nested function
(define (test a b)
(if (= a b)
(raise "equal")
else
(+ a b)))
(with-exception-handler
(lambda (x)
(print "exception: " x))
(lambda ()
(print (test 1 2))
(print (test 7 7))))
; exception from exception
(with-exception-handler
(lambda (x)
(print "exception 1: " x))
(lambda ()
(with-exception-handler
(lambda (y)
(print "exception 2: " y)
(raise y))
(lambda ()
(print (test 17 12))
(print (test 77 77))))))
(print "done.")