Skip to content

Instantly share code, notes, and snippets.

@jordanorelli
Created July 10, 2014 16:33
Show Gist options
  • Save jordanorelli/4aa9fffafb0ba10ce2ec to your computer and use it in GitHub Desktop.
Save jordanorelli/4aa9fffafb0ba10ce2ec to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main() {
err := fmt.Errorf("this is an error.")
// these two lines print the same thing when err is non-nil
fmt.Printf("%v\n", err)
fmt.Printf("%s\n", err.Error())
err = nil
fmt.Printf("%v\n", err) // this is safe
fmt.Printf("%s\n", err.Error()) // this is a panic
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment