1
2
3
4
5
6
7
8
9 exclusive-container error-or:_elem [
10 error:text
11 value:_elem
12 ]
13
14 def main [
15 local-scope
16 no-exception:bool <- copy 0/false
17 foo 0/no-exception
18 raise-exception:bool <- copy 1/true
19 foo 1/raise-exception
20 ]
21
22
23 def foo raise-exception?:bool [
24 local-scope
25 load-inputs
26
27
28
29
30
31
32
33
34 _, result:error-or:num <- call-with-continuation-mark 999/exception-tag, f, raise-exception?
35 {
36 val:num, normal-exit?:bool <- maybe-convert result, value:variant
37 break-unless normal-exit?
38 $print [normal exit; result ] val 10/newline
39 }
40 {
41 err:text, error-exit?:bool <- maybe-convert result, error:variant
42 break-unless error-exit?
43 $print [error caught: ] err 10/newline
44 }
45 ]
46
47
48
49 def f raise-exception?:bool -> result:error-or:num [
50 local-scope
51 load-inputs
52 {
53 break-unless raise-exception?
54
55 result <- merge 0/error, [error will robinson!]
56 return-continuation-until-mark 999/exception-tag, result
57 }
58
59 result <- merge 1/value, 34
60 return-continuation-until-mark 999/exception-tag, result
61
62 result <- merge 1/value, 0
63 return result
64 ]