aboutsummaryrefslogtreecommitdiff
path: root/src/errors
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2020-04-12 10:00:27 -0400
committerJonathan Amsterdam <jba@google.com>2020-04-13 20:04:56 +0000
commit7b5303d08a1b589708d6bad3d7015d9856273aac (patch)
tree354e1228527532832e30a65f04f20158999b669c /src/errors
parent82fcf749bde1aae839ce520edfff04d2daf70987 (diff)
downloadgo-7b5303d08a1b589708d6bad3d7015d9856273aac.tar.gz
go-7b5303d08a1b589708d6bad3d7015d9856273aac.zip
errors: add example for Is
Add ExampleIs to illustrate how errors.Is works. Updates #31716. Updates #38369. Change-Id: I1b9a6667614635aa3a5ed8b2c108d8eb6f35748b Reviewed-on: https://go-review.googlesource.com/c/go/+/228038 Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/errors')
-rw-r--r--src/errors/wrap_test.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/errors/wrap_test.go b/src/errors/wrap_test.go
index 590c1857e3..4a4a732c9b 100644
--- a/src/errors/wrap_test.go
+++ b/src/errors/wrap_test.go
@@ -238,6 +238,19 @@ func (errorUncomparable) Is(target error) bool {
return ok
}
+func ExampleIs() {
+ if _, err := os.Open("non-existing"); err != nil {
+ if errors.Is(err, os.ErrNotExist) {
+ fmt.Println("file does not exist")
+ } else {
+ fmt.Println(err)
+ }
+ }
+
+ // Output:
+ // file does not exist
+}
+
func ExampleAs() {
if _, err := os.Open("non-existing"); err != nil {
var pathError *os.PathError