errors library explained
This commit is contained in:
parent
c7da2836f7
commit
543286da57
32
error_handling/demo2.go
Normal file
32
error_handling/demo2.go
Normal file
|
@ -0,0 +1,32 @@
|
|||
package error_handling
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
|
||||
func GuessIt(guess int) (string, error){
|
||||
|
||||
number_in_mind := 50
|
||||
|
||||
if guess < 1 || guess > 100{
|
||||
return "", errors.New("Type a number between 1 and 100 ")
|
||||
}
|
||||
|
||||
if guess > number_in_mind{
|
||||
return "Type a small number", nil
|
||||
}
|
||||
|
||||
if guess < number_in_mind{
|
||||
return "Type a bigger number", nil
|
||||
}
|
||||
|
||||
return "You did it", nil
|
||||
}
|
||||
|
||||
func Demo2() {
|
||||
message, error:= GuessIt(101)
|
||||
fmt.Println(message)
|
||||
fmt.Println(error)
|
||||
}
|
Loading…
Reference in New Issue
Block a user