Reputation: 13758
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.
Upvotes: 3
Views: 4269
Reputation: 77985
Try using the fmt
package
import "fmt"
...
return fmt.Sprint("Cannot Sqrt negative number ", float64(e))
Upvotes: 9