Created
August 26, 2016 19:14
-
-
Save roustem/827456103c02aadf8ae29ca32579e3a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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