Last active
June 8, 2021 06:46
-
-
Save scriptonist/788c1743d8f9f86dfa96e3ec4647608e to your computer and use it in GitHub Desktop.
This file contains 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 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") | |
} |
This file contains 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 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