I'm working through the Go tour and in the Errors exercise it mentions that calling Sprint(f) in your Error function will result in an issue, which is an infinite loop. Why this occurs is explained here: Error, infinite loop
In my first implementation though I used Sprintf with the %f verb:
func (e ErrNegativeSqrt) Error() string {
return fmt.Sprintf("cannot Sqrt negative number: %f", e)
}
This seems to avoid the issue and I was wondering if this is because the %f verb is expecting a float so it forces it to treat e as a float? The tour mentioned that assignment requires explicit conversion, however I assume that doesn't effect this case?
Or am I completely off the mark and something else is going on here?