push all exercices
This commit is contained in:
BIN
ch9/1/ch9_1.exe
Normal file
BIN
ch9/1/ch9_1.exe
Normal file
Binary file not shown.
33
ch9/1/ch9_1.go
Normal file
33
ch9/1/ch9_1.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type SentinelError string
|
||||
|
||||
func (s SentinelError) Error() string {
|
||||
return string(s)
|
||||
}
|
||||
|
||||
func (s SentinelError) Is(target error) bool {
|
||||
return s.Error() == target.Error()
|
||||
}
|
||||
|
||||
const (
|
||||
ErrId = SentinelError("Wrong ID")
|
||||
ErrTest = SentinelError("Wrong Test")
|
||||
)
|
||||
|
||||
func main() {
|
||||
errId := ErrId
|
||||
errTest := ErrTest
|
||||
fmt.Printf("Does ErrId found: %b\n", errors.Is(errId, ErrId))
|
||||
|
||||
fmt.Printf("Does ErrTest found: %b\n", errors.Is(errId, ErrTest))
|
||||
|
||||
fmt.Printf("Does ErrId found: %b\n", errors.Is(errTest, ErrId))
|
||||
|
||||
fmt.Printf("Does ErrTest found: %b\n", errors.Is(errTest, ErrTest))
|
||||
}
|
||||
3
ch9/1/go.mod
Normal file
3
ch9/1/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module ch9_1
|
||||
|
||||
go 1.25.0
|
||||
Reference in New Issue
Block a user