Skip to content

Instantly share code, notes, and snippets.

@roustem
Created August 26, 2016 19:14
Show Gist options
  • Save roustem/827456103c02aadf8ae29ca32579e3a4 to your computer and use it in GitHub Desktop.
Save roustem/827456103c02aadf8ae29ca32579e3a4 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type myError struct {
Message string
}
func (m *myError) Error() string {
return "MyError: " + m.Message
}
func x() error {
// return errors.New("Hello")
// return &myError{Message: "huh"}
return nil
}
func main() {
err := x()
switch e := err.(type) {
case *myError:
fmt.Println("here we go: ", e)
default:
fmt.Println("something else")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment