-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (60 loc) · 1.75 KB
/
main.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
65
66
67
68
69
70
package main
import (
"fmt"
"github.com/fioepq9/errors"
)
func foo(method string) error {
switch method {
case "new":
return errors.New("foo")
case "wrap":
return errors.Wrap(foo("new"), "this is wrapeed foo")
default:
panic("invalid method")
}
}
func bar(method string) error {
switch method {
case "new":
return foo("new")
case "wrap":
return errors.Wrap(foo("wrap"), "this is wrapeed bar")
default:
panic("invalid method")
}
}
func baz(method string) error {
switch method {
case "new":
return bar("new")
case "wrap":
return errors.Wrap(bar("wrap"), "this is wrapeed baz")
default:
panic("invalid method")
}
}
func main() {
errors.C.Style = errors.StyleStack
fmt.Println(baz("new"))
fmt.Println("=====================================")
fmt.Println(baz("wrap"))
}
/*
foo
D:/code/projects/errorsexamples/quickstart/main.go:12 (0x457eda) main.foo()
D:/code/projects/errorsexamples/quickstart/main.go:23 (0x457f9a) main.bar()
D:/code/projects/errorsexamples/quickstart/main.go:34 (0x45805a) main.baz()
D:/code/projects/errorsexamples/quickstart/main.go:45 (0x458133) main.main()
D:/apps/scoop/apps/go/current/src/runtime/proc.go:267 (0x405231) runtime.main()
=====================================
foo
D:/code/projects/errorsexamples/quickstart/main.go:12 (0x457eda) main.foo()
this is wrapeed foo
D:/code/projects/errorsexamples/quickstart/main.go:14 (0x457f15) main.foo()
this is wrapeed bar
D:/code/projects/errorsexamples/quickstart/main.go:25 (0x457fd5) main.bar()
this is wrapeed baz
D:/code/projects/errorsexamples/quickstart/main.go:36 (0x458095) main.baz()
D:/code/projects/errorsexamples/quickstart/main.go:49 (0x4581bb) main.main()
D:/apps/scoop/apps/go/current/src/runtime/proc.go:267 (0x405231) runtime.main()
*/