Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit b402999

Browse files
committed
more examples
1 parent 63e2913 commit b402999

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

example_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,35 @@
11
package errors_test
22

33
import (
4-
"errors"
54
"fmt"
5+
6+
"github.com/pkg/errors"
67
)
78

89
func ExampleNew() {
910
err := errors.New("whoops")
10-
fmt.Println(err.Error())
11+
fmt.Println(err)
1112

1213
// Output: whoops
1314
}
15+
16+
func ExampleWrap() {
17+
cause := errors.New("whoops")
18+
err := errors.Wrap(cause, "oh noes")
19+
fmt.Println(err)
20+
21+
// Output: oh noes: whoops
22+
}
23+
24+
func fn() error {
25+
return errors.Wrap(errors.Wrap(errors.Wrap(errors.New("error"), "inner"), "middle"), "outer")
26+
}
27+
28+
func ExampleCause() {
29+
err := fn()
30+
fmt.Println(err)
31+
fmt.Println(errors.Cause(err))
32+
33+
// Output: outer: middle: inner: error
34+
// error
35+
}

0 commit comments

Comments
 (0)