Handling errors

Predict the output of the following code snippet.

func Sqrt(num float64)(float64, error) {
 if(num < 0){
 return 0, errors.New("The result is a Complex Number")
 }
 return math.Sqrt(num), nil
}

func main() {
 output, error:= Sqrt(-4)

 if error != nil {
 fmt.Println(error)
 }else {
 fmt.Println(output)
 }
 
 output, error = Sqrt(256)

 if error != nil {
 fmt.Println(error)
 }else {
 fmt.Println(output)
 }
}
Options

1.2

16

2.16

2

3.Error

4.16

The result is a Complex Number

5.The result is a Complex Number

16

Related Posts

Close Bitnami banner
Bitnami