Skip to content

Commit

Permalink
more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
davecheney committed Apr 22, 2016
1 parent 63e2913 commit b402999
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
package errors_test

import (
"errors"
"fmt"

"github.com/pkg/errors"
)

func ExampleNew() {
err := errors.New("whoops")
fmt.Println(err.Error())
fmt.Println(err)

// Output: whoops
}

func ExampleWrap() {
cause := errors.New("whoops")
err := errors.Wrap(cause, "oh noes")
fmt.Println(err)

// Output: oh noes: whoops
}

func fn() error {
return errors.Wrap(errors.Wrap(errors.Wrap(errors.New("error"), "inner"), "middle"), "outer")
}

func ExampleCause() {
err := fn()
fmt.Println(err)
fmt.Println(errors.Cause(err))

// Output: outer: middle: inner: error
// error
}

0 comments on commit b402999

Please sign in to comment.