-
Notifications
You must be signed in to change notification settings - Fork 171
/
error.go
64 lines (55 loc) · 1.46 KB
/
error.go
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
60
61
62
63
64
package vm
import (
"fmt"
)
var (
// UndefinedMethodErrorClass ...
UndefinedMethodErrorClass *RClass
// ArgumentErrorClass ...
ArgumentErrorClass *RClass
// TypeErrorClass ...
TypeErrorClass *RClass
// UnsupportedMethodClass
UnsupportedMethodClass *RClass
)
const (
// UndefinedMethodError describes the error type in string
UndefinedMethodError = "UndefinedMethodError"
// ArgumentError describes the error type in string
ArgumentError = "ArgumentError"
// TypeError describes the error type in string
TypeError = "TypeError"
// UnsupportedMethodError describes the error type in string
UnsupportedMethodError = "UnsupportedMethodError"
)
func initErrorClasses() {
bc := createBaseClass(UndefinedMethodError)
UndefinedMethodErrorClass = &RClass{BaseClass: bc}
bc = createBaseClass(ArgumentError)
ArgumentErrorClass = &RClass{BaseClass: bc}
bc = createBaseClass(TypeError)
TypeErrorClass = &RClass{BaseClass: bc}
bc = createBaseClass(UnsupportedMethodError)
UnsupportedMethodClass = &RClass{BaseClass: bc}
}
// Error ...
type Error struct {
Class *RClass
Message string
}
// toString ...
func (e *Error) toString() string {
return "ERROR: " + e.Message
}
func (e *Error) toJSON() string {
return e.toString()
}
func (e *Error) returnClass() Class {
return e.Class
}
func initErrorObject(errorType *RClass, format string, args ...interface{}) *Error {
return &Error{
Class: errorType,
Message: fmt.Sprintf(errorType.Name+": "+format, args...),
}
}