Files
learning_go/ch9/1/ch9_1.go
2026-02-21 14:09:13 +03:00

34 lines
623 B
Go

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))
}