Исходники и презентации
This commit is contained in:
21
lessons/errors/errors_value_checking/main.go
Normal file
21
lessons/errors/errors_value_checking/main.go
Normal file
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
var ErrDatabaseProblem = errors.New("database problem")
|
||||
|
||||
func GetDataFromDB() error {
|
||||
return fmt.Errorf("failed to get data: %w", ErrDatabaseProblem)
|
||||
}
|
||||
|
||||
func main() {
|
||||
err := GetDataFromDB()
|
||||
if err == ErrDatabaseProblem {
|
||||
fmt.Println(err.Error())
|
||||
} else if err != nil {
|
||||
fmt.Println("unknown error")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user