1
0
mirror of https://github.com/golang/go synced 2024-11-23 22:30:05 -07:00

errors: add errors.Unwrap example

Change-Id: Id2336a6059f7a8d627e6c0661a4d4c05485b65f3
Reviewed-on: https://go-review.googlesource.com/c/go/+/355589
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Cherry Mui <cherryyz@google.com>
Trust: Robert Findley <rfindley@google.com>
This commit is contained in:
jiahua wang 2021-10-13 22:16:37 +08:00 committed by Ian Lance Taylor
parent 90462dfc3a
commit fb8b1764d8

View File

@ -265,3 +265,13 @@ func ExampleAs() {
// Output:
// Failed at path: non-existing
}
func ExampleUnwrap() {
err1 := errors.New("error1")
err2 := fmt.Errorf("error2: [%w]", err1)
fmt.Println(err2)
fmt.Println(errors.Unwrap(err2))
// Output
// error2: [error1]
// error1
}