|
0 |
;'<<SPEC'
|
|
1 |
|
|
2 |
### `catch` ###
|
|
3 |
|
|
4 |
-> Tests for functionality "Evaluate Robin Expression (with literal and list)"
|
|
5 |
|
|
6 |
`catch` handles error values.
|
|
7 |
|
|
8 |
TODO: this is written as if catch handles exceptions, but it doesn't anymore.
|
|
9 |
|
|
10 |
If an exception is raised when evaluating the final argument of
|
|
11 |
`catch`, the exception value is bound to the symbol given as the
|
|
12 |
first argument of `catch`, and the second argument of `catch` is
|
|
13 |
evaluated in that new environment.
|
|
14 |
|
|
15 |
| (catch error (list error #f)
|
|
16 |
| (raise (literal (nasty-value 999999))))
|
|
17 |
= ((nasty-value 999999) #f)
|
|
18 |
|
|
19 |
If an exception is raised in the body of a macro that is applied
|
|
20 |
in the context of a `catch`, it will still be catched.
|
|
21 |
|
|
22 |
| (catch error (list error #f)
|
|
23 |
| ((macro (self args env) (raise (literal (nasty-value 1111)))) joe))
|
|
24 |
= ((nasty-value 1111) #f)
|
|
25 |
|
|
26 |
If nothing is raised, `catch` will evaluate to whatever its body
|
|
27 |
evaluated to.
|
|
28 |
|
|
29 |
| (catch error (list error #f) 42)
|
|
30 |
= 42
|
|
31 |
|
|
32 |
The innermost `catch` will catch the exception.
|
|
33 |
|
|
34 |
| (catch error (list error 5)
|
|
35 |
| (catch error (list error 9)
|
|
36 |
| (raise (literal derpy-value))))
|
|
37 |
= (derpy-value 9)
|
|
38 |
|
|
39 |
An exception raised from within an exception handler is
|
|
40 |
caught by the next innermost exception handler.
|
|
41 |
|
|
42 |
| (catch error (list error 5)
|
|
43 |
| (catch error (list error 9)
|
|
44 |
| (catch error (raise (list error error))
|
|
45 |
| (raise 7))))
|
|
46 |
= ((7 7) 9)
|
|
47 |
|
|
48 |
`catch` expects its first argument to be a symbol.
|
|
49 |
|
|
50 |
| (catch (3 4) (list error #f) 42)
|
|
51 |
? uncaught exception: (illegal-arguments ((3 4) (list error #f) 42))
|
|
52 |
|
|
53 |
`catch` expects exactly three arguments.
|
|
54 |
|
|
55 |
| (catch error (list error #f))
|
|
56 |
? uncaught exception: (illegal-arguments (error (list error #f)))
|
|
57 |
|
|
58 |
| (catch error (list error #f) 42 43)
|
|
59 |
? uncaught exception: (illegal-arguments (error (list error #f) 42 43))
|
|
60 |
|
|
61 |
-> Tests for functionality "Evaluate Robin Expression (with Small)"
|
|
62 |
|
|
63 |
`catch` handles error values, and this does not include the environment
|
|
64 |
in which the error value was produced.
|
|
65 |
|
|
66 |
| (catch error (list flop error)
|
|
67 |
| (bind flop 1
|
|
68 |
| (raise 2)))
|
|
69 |
? uncaught exception: (unbound-identifier flop)
|
|
70 |
|
|
71 |
`catch` handles error values, and this does not include the environment
|
|
72 |
in which the error value was produced.
|
|
73 |
|
|
74 |
| (bind flop (fun (x) (raise x))
|
|
75 |
| (list
|
|
76 |
| (catch error (list 55 error) (flop 44))
|
|
77 |
| (catch error (list 66 error) (flop 44))))
|
|
78 |
= ((55 44) (66 44))
|
|
79 |
|
|
80 |
'<<SPEC'
|
|
81 |
|
|
82 |
(require catch)
|