Error Custom example
This commit is contained in:
parent
543286da57
commit
0418380fd2
21
error_handling/demo3.go
Normal file
21
error_handling/demo3.go
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
package error_handling
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
type borderException struct{
|
||||||
|
parameter int
|
||||||
|
message string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *borderException) Error() string{
|
||||||
|
return fmt.Sprintf("%d ---- %s", b.parameter, b.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GuessIt2(guess int) (string, error){
|
||||||
|
if guess < 1 || guess > 100{
|
||||||
|
return "", &borderException{guess, "Out of border"}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "You did it", nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user