Skip to content

Instantly share code, notes, and snippets.

@scriptonist
Last active June 8, 2021 06:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scriptonist/788c1743d8f9f86dfa96e3ec4647608e to your computer and use it in GitHub Desktop.
Save scriptonist/788c1743d8f9f86dfa96e3ec4647608e to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
type Err struct {
m string
}
func (e *Err) Error() string {
return e.m
}
func getError() *Err {
return nil
}
func main() {
err := fmt.Errorf("test")
err = getError()
if err != nil {
fmt.Printf("got error")
return
}
fmt.Printf("no error")
}
package main
import (
"fmt"
)
type CustomError interface {
additionalInfo() string
error
}
type Err struct {
m string
}
func (e *Err) additionalInfo() string {
return "additional info"
}
func (e *Err) Error() string {
return e.m
}
func getError() CustomError {
return nil
}
func main() {
err := fmt.Errorf("test")
err = getError()
if err != nil {
fmt.Printf("got error")
return
}
fmt.Printf("no error")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment