summaryrefslogtreecommitdiff
path: root/libgo/go/errors
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-07-27 22:27:54 -0700
committerIan Lance Taylor <iant@golang.org>2020-08-01 11:21:40 -0700
commitf75af8c1464e948b5e166cf5ab09ebf0d82fc253 (patch)
tree3ba3299859b504bdeb477727471216bd094a0191 /libgo/go/errors
parent75a23e59031fe673fc3b2e60fd1fe5f4c70ecb85 (diff)
downloadgcc-f75af8c1464e948b5e166cf5ab09ebf0d82fc253.tar.gz
libgo: update to go1.15rc1
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/245157
Diffstat (limited to 'libgo/go/errors')
-rw-r--r--libgo/go/errors/wrap.go2
-rw-r--r--libgo/go/errors/wrap_test.go13
2 files changed, 14 insertions, 1 deletions
diff --git a/libgo/go/errors/wrap.go b/libgo/go/errors/wrap.go
index 272d056b318..b82ca34b46f 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 590c1857e37..4a4a732c9be 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