-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.go
48 lines (36 loc) · 871 Bytes
/
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
package mruby
import "fmt"
var _ RException = &Exception{}
type RException interface {
RBasic
error
SetMessage(string)
}
type Exception struct {
Object
message string
}
func (e *Exception) Error() string {
return e.message
}
func (e *Exception) SetMessage(message string) {
e.message = message
}
func (mrb *State) Raise(excType RClass, message string) {
mrb.ExceptionRaise(mrb.ExceptionNewString(excType, message))
}
func (mrb *State) Raisef(excType RClass, format string, args ...any) {
mrb.Raise(excType, fmt.Sprintf(format, args...))
}
func (mrb *State) ExceptionRaise(excValue Value) {
exc, ok := excValue.(RException)
if !ok {
mrb.Raise(nil, "exception object expected")
}
panic(exc)
}
func (mrb *State) ExceptionNewString(class RClass, message string) RException {
exc := mrb.AllocException(class)
exc.SetMessage(message)
return exc
}