diff --git a/error_handling/demo3.go b/error_handling/demo3.go new file mode 100644 index 0000000..e3bb0d8 --- /dev/null +++ b/error_handling/demo3.go @@ -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 +} + diff --git a/main.go b/main.go index 9ffe7b6..c8a856b 100644 --- a/main.go +++ b/main.go @@ -124,4 +124,5 @@ func main() { error_handling.Demo1() interfaces.Demo3() error_handling.Demo2() + fmt.Println(error_handling.GuessIt2(102)) }