Source file
src/errors/example_test.go
1
2
3
4
5 package errors_test
6
7 import (
8 "fmt"
9 "time"
10 )
11
12
13 type MyError struct {
14 When time.Time
15 What string
16 }
17
18 func (e MyError) Error() string {
19 return fmt.Sprintf("%v: %v", e.When, e.What)
20 }
21
22 func oops() error {
23 return MyError{
24 time.Date(1989, 3, 15, 22, 30, 0, 0, time.UTC),
25 "the file system has gone away",
26 }
27 }
28
29 func Example() {
30 if err := oops(); err != nil {
31 fmt.Println(err)
32 }
33
34 }
35
View as plain text