http://play.golang.org/p/xjs-jwMsr7
I have this function
func (e *MyError) Error() string {
return fmt.Sprintf("AT %v, %s", e.When, e.What)
}
But
as you see below, I never called it but how come it is called in the final output?
type MyError struct {
When time.Time
What string
}
func (e *MyError) Error() string {
return fmt.Sprintf("AT %v, %s", e.When, e.What)
}
func run() error {
return &MyError{
time.Now(), "it didn't work",
}
}
func main() {
if err := run(); err != nil {
fmt.Println(err)
}
}