-
Notifications
You must be signed in to change notification settings - Fork 4
/
throwables.go
45 lines (37 loc) · 1.54 KB
/
throwables.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
package throw
// IllegalValue is to indicate that an argument provided to a calling function is incorrect
// This error captures the topmost entry of caller's stack.
func IllegalValue() error {
return newMsg("illegal value", 0)
}
// IllegalState is to indicate that an internal state of a function/object is incorrect or unexpected
// This error captures the topmost entry of caller's stack.
func IllegalState() error {
return newMsg("illegal state", 0)
}
// Unsupported is to indicate that a calling function is unsupported intentionally and will remain so for awhile
// This error captures the topmost entry of caller's stack.
func Unsupported() error {
return newMsg("unsupported", 0)
}
// NotImplemented is to indicate that a calling function was not yet implemented, but it is expected to be completed soon
// This error captures the topmost entry of caller's stack.
func NotImplemented() error {
return newMsg("not implemented", 0)
}
// Impossible is to indicate that the point can never be reached.
// This error captures the topmost entry of caller's stack.
func Impossible() error {
return newMsg("impossible", 0)
}
// FailHere creates an error that captures the topmost entry of caller's stack.
func FailHere(msg string) error {
return newMsg(msg, 0)
}
// FailCaller creates an error that captures the entry of caller's stack after skipping (skipFrames).
func FailCaller(msg string, skipFrames int) error {
return newMsg(msg, skipFrames)
}
func newMsg(msg string, skipFrames int) msgWrap {
return msgWrap{st: CaptureStackTop(skipFrames + 2), msg: msg}
}