-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherror.go
More file actions
28 lines (23 loc) · 684 Bytes
/
Copy patherror.go
File metadata and controls
28 lines (23 loc) · 684 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
// Copyright (c) 2023, Peter Ohler, All rights reserved.
package slip
import (
"fmt"
)
// ErrorSymbol is the symbol with a value of "error".
const ErrorSymbol = Symbol("error")
// ErrorNew returns an Error object that can then be used with a call to panic.
func ErrorNew(s *Scope, depth int, format string, args ...any) Object {
c := FindClass("error")
if c == nil {
c = UserPkg.FindClass("error")
}
obj := c.MakeInstance()
obj.Init(s, List{
Symbol(":message"), String(fmt.Sprintf(format, args...)),
}, depth)
return obj
}
// ErrorPanic raises an error.
func ErrorPanic(s *Scope, depth int, format string, args ...any) {
panic(ErrorNew(s, depth, format, args...))
}