Instantly share code, notes, and snippets.

@abraithwaite /errors.go Secret
Created Aug 27, 2018

Embed
What would you like to do?
package main
import "fmt"
type customErr struct {
Value string
}
func (c *customErr) Error() string {
return c.Value
}
func DoSomething(fail bool) *customErr {
if fail {
return &customErr{Value: "failed"}
}
return nil
}
func main() {
var err error
err = DoSomething(true)
if err != nil {
fmt.Println(err)
}
err = DoSomething(false)
if err != nil {
fmt.Println("also failed")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment