-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathmain.go
More file actions
33 lines (25 loc) · 513 Bytes
/
Copy pathmain.go
File metadata and controls
33 lines (25 loc) · 513 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
package main
import (
"errors"
"fmt"
"io"
)
var ErrOne = fmt.Errorf("one")
var ErrTwo = fmt.Errorf("two")
func main() {
// Using errors.Join
join := errors.Join(ErrOne, ErrTwo)
fmt.Printf("%+v\n", join)
if errors.Is(join, ErrOne) {
fmt.Println("One!")
}
if errors.Is(join, ErrTwo) {
fmt.Println("Two!")
}
// Using fmt.Errorf with multiple %w
efmt := fmt.Errorf("%w, %w", errors.New("fmt"), io.EOF)
fmt.Printf("%+v\n", efmt)
if errors.Is(efmt, io.EOF) {
fmt.Println("End of File")
}
}