...
Source file
src/golang.org/x/xerrors/example_FormatError_test.go
1
2
3
4
5 package xerrors_test
6
7 import (
8 "fmt"
9
10 "golang.org/x/xerrors"
11 )
12
13 type MyError2 struct {
14 Message string
15 frame xerrors.Frame
16 }
17
18 func (m *MyError2) Error() string {
19 return m.Message
20 }
21
22 func (m *MyError2) Format(f fmt.State, c rune) {
23 xerrors.FormatError(m, f, c)
24 }
25
26 func (m *MyError2) FormatError(p xerrors.Printer) error {
27 p.Print(m.Message)
28 if p.Detail() {
29 m.frame.Format(p)
30 }
31 return nil
32 }
33
34 func ExampleFormatError() {
35 err := &MyError2{Message: "oops", frame: xerrors.Caller(1)}
36 fmt.Printf("%v\n", err)
37 fmt.Println()
38 fmt.Printf("%+v\n", err)
39 }
40
View as plain text