https://github.com/akkartik/mu/blob/master/exception2.mu
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 foo false/no-exception
17 foo true/raise-exception
18 ]
19
20
21 def foo raise-exception?:bool [
22 local-scope
23 load-inputs
24
25
26
27
28
29
30
31
32 _, result:error-or:num <- call-with-continuation-mark 999/exception-tag, f, raise-exception?
33 {
34 val:num, normal-exit?:bool <- maybe-convert result, value:variant
35 break-unless normal-exit?
36 $print [normal exit; result ] val 10/newline
37 }
38 {
39 err:text, error-exit?:bool <- maybe-convert result, error:variant
40 break-unless error-exit?
41 $print [error caught: ] err 10/newline
42 }
43 ]
44
45
46
47 def f raise-exception?:bool -> result:error-or:num [
48 local-scope
49 load-inputs
50 {
51 break-unless raise-exception?
52
53 result <- merge 0/error, [error will robinson!]
54 return-continuation-until-mark 999/exception-tag, result
55 }
56
57 result <- merge 1/value, 34
58 return-continuation-until-mark 999/exception-tag, result
59
60 result <- merge 1/value, 0
61 pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5