The testing department gave you a panic handler function:
func panicHandler() {
switch recover() {
case "negative":
fmt.Println("Number must be positive")
case "zero":
fmt.Println("Number must have a non-zero value")
case "bounds":
fmt.Println("Number goes out of bounds")
case "non-prime":
fmt.Println("Number is non-prime")
case nil:
fmt.Println("Number is suitable!")
}
}
This function reports if any of the four errors occurred with the number, and returns the nil case if the number is suitable. You need to write the required code to check a given number, and then output a panic signal if the number doesn't satisfy the following conditions:
- the number is positive;
- the number is not equal to
0; - the number is less or equal to
100; - the number is prime.
Tip: The recover() function works only inside a deferred call.