Error Custom example

This commit is contained in:
Mert Gör ☭ 2024-03-16 16:48:55 +03:00
parent 543286da57
commit 0418380fd2
Signed by: hwpplayer1
GPG Key ID: 03E547D043AB6C8F
2 changed files with 22 additions and 0 deletions

21
error_handling/demo3.go Normal file
View 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
}

View File

@ -124,4 +124,5 @@ func main() {
error_handling.Demo1()
interfaces.Demo3()
error_handling.Demo2()
fmt.Println(error_handling.GuessIt2(102))
}