I am trying to solve this: http://tour.golang.org/#58
Here is what I have done;
#imports omitted
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
return "Cannot Sqrt negative number: " + string(e)
}
func Sqrt(f float64) (float64, error) {
if f < 0 {
return 0, ErrNegativeSqrt(1)
}
# calculate z here...
return z, nil
}
# main omitted
I have also tried e.String()
and e.string()
but those didn't work too...