-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_test.go
More file actions
38 lines (31 loc) · 902 Bytes
/
example_test.go
File metadata and controls
38 lines (31 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package errors_test
import (
"fmt"
"github.com/Bowery/errors"
"io"
"strconv"
)
func ExampleNewStackError() {
err := errors.NewStackError(io.EOF)
stackErr := errors.IsStackError(err)
fmt.Println(stackErr.Err == io.EOF) // The underlying error.
fmt.Println(stackErr.Trace.Exception.Message)
for _, frame := range stackErr.Trace.Frames {
fmt.Println("File:", frame.File+":"+strconv.Itoa(frame.Line), "at", frame.Method)
}
// Or use Stack to print a nicely formatted stack trace.
fmt.Println(stackErr.Stack())
}
func ExampleIsStackError() {
err := errors.NewStackError(errors.New("github.com/Bowery/errors: Some error happened"))
stackErr := errors.IsStackError(err)
if stackErr != nil {
fmt.Println("Yes it's a stack error.")
fmt.Println(stackErr.Stack())
}
err = io.EOF
if errors.IsStackError(err) == nil {
fmt.Println("It is not a stack error.")
fmt.Println(err)
}
}