In Golang, how to convert an error to a string?

In Golang, fmt.Println(err) can print out the error err. But how to convert an error to a string explicitely?

asked Aug 5, 2016 by anonymous

1 Answer

In Go, the error type has an interface

type error interface {
    Error() string


So, for an error err, you can call


to get a string representing err.

answered Oct 10, 2016 by Eric Z Ma (44,280 points)

Please log in or register to answer this question.

Related questions

1 answer
1 answer
1 answer
0 answers
1 answer
1 answer
Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost