I want to test how certain code handles errors.
I want a function to return an error.
I have tried typing return 0/0
but then my application won't build
How can I force return an error?
I want to test how certain code handles errors.
I want a function to return an error.
I have tried typing return 0/0
but then my application won't build
How can I force return an error?
you can return errors like this:
func ReturnError() (string, error){
return "", fmt.Errorf("this is an %s error", "internal server")
// or
return "", errors.New("this is an error")
}