diff options
Diffstat (limited to 'libgo/go/errors')
-rw-r--r-- | libgo/go/errors/wrap.go | 2 | ||||
-rw-r--r-- | libgo/go/errors/wrap_test.go | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/libgo/go/errors/wrap.go b/libgo/go/errors/wrap.go index 272d056..b82ca34 100644 --- a/libgo/go/errors/wrap.go +++ b/libgo/go/errors/wrap.go @@ -70,7 +70,7 @@ func Is(err, target error) bool { // setting target. // // An error type might provide an As method so it can be treated as if it were a -// a different error type. +// different error type. // // As panics if target is not a non-nil pointer to either a type that implements // error, or to any interface type. diff --git a/libgo/go/errors/wrap_test.go b/libgo/go/errors/wrap_test.go index 590c185..4a4a732 100644 --- a/libgo/go/errors/wrap_test.go +++ b/libgo/go/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 |