Created
April 29, 2021 22:21
-
-
Save gloriousCode/1da093257555669e2528b1469d5c01a0 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
func ReturnErr() error { | |
return errors.New("hello") | |
} | |
func DeferErr() error { | |
return errors.New("deferred") | |
} | |
func HandleErrs() error { | |
var err error | |
defer func() { | |
err = DeferErr() | |
if err != nil { | |
fmt.Println("deferred" + err.Error()) | |
} | |
}() | |
err = ReturnErr() | |
if err != nil { | |
return err | |
} | |
return nil | |
} | |
func TestDeferErr(t *testing.T) { | |
err := HandleErrs() | |
if err != nil { | |
t.Error("the big one" + err.Error()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment