diff options
| author | jiahua wang <wjh180909@gmail.com> | 2021-10-13 22:16:37 +0800 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2021-11-05 21:28:50 +0000 |
| commit | fb8b1764d8e8afdaf5d8fd00af3720e42d96ad9c (patch) | |
| tree | 923a3013b009e89fac0f3066f8d249302c043811 /src/errors/wrap_test.go | |
| parent | 90462dfc3aa99649de90bb587af56a9cb0214665 (diff) | |
| download | go-fb8b1764d8e8afdaf5d8fd00af3720e42d96ad9c.tar.xz | |
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>
Diffstat (limited to 'src/errors/wrap_test.go')
| -rw-r--r-- | src/errors/wrap_test.go | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/errors/wrap_test.go b/src/errors/wrap_test.go index 6f66e99c4a..a22fee2f04 100644 --- a/src/errors/wrap_test.go +++ b/src/errors/wrap_test.go @@ -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 +} |
