Skip to content

Commit

Permalink
wrap error examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Guvanchhojamov committed Dec 17, 2023
1 parent 22e2793 commit 70367d1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions practic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,32 @@ import "fmt"

func main() {
fmt.Println("some practics")
//if err := foo.Open("foo"); err != nil {
// if foo.IsNotFoundError(err) {
// // handle
// } else {
// panic("unknown error")
// }
//}
}

// package foo

type errNotFound struct {
file string
}

func (e errNotFound) Error() string {
return fmt.Sprintf("file %q not found", e.file)
}

func IsNotFoundError(err error) bool {
_, ok := err.(errNotFound)
return ok
}

func Open(file string) error {
return errNotFound{file: file}
}

// package bar

0 comments on commit 70367d1

Please sign in to comment.