-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherror.go
More file actions
40 lines (38 loc) · 764 Bytes
/
error.go
File metadata and controls
40 lines (38 loc) · 764 Bytes
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
package lisp
import "fmt"
func init() {
Add("raise", func(t []Token, p *Lisp) (Token, error) {
if len(t) != 1 {
return None, ErrParaNum
}
ans, err := p.Exec(t[0])
if err != nil {
return None, err
}
if ans.Kind != String {
return None, ErrFitType
}
return None, fmt.Errorf(ans.Text.(string))
})
Add("catch", func(t []Token, p *Lisp) (Token, error) {
if len(t) != 1 {
return None, ErrParaNum
}
_, err := p.Exec(t[0])
if err != nil {
return Token{String, fmt.Sprint(err)}, nil
}
return None, nil
})
Add("error", func(t []Token, p *Lisp) (Token, error) {
if len(t) != 1 {
return None, ErrParaNum
}
ans, err := p.Exec(t[0])
if err != nil {
fmt.Println(err)
return None, err
}
return ans, nil
})
}