We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go version
$ go version go1.13.10 linux/amd64
Yes
go env
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="/go/bin" GOCACHE="/.cache/go-build" GOENV="/.config/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/snap/go/5646" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/snap/go/5646/pkg/tool/linux_amd64" GCCGO="gccgo" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build798787028=/tmp/go-build -gno-record-gcc-switches"
Run simple code: (https://play.golang.org/p/z2YsplDZOfp)
package main import ( "fmt" ) func a() error { err := fmt.Errorf("Errorrrrrrooo") defer func() { err = nil }() return err } func b() (err error) { err = fmt.Errorf("Errorrrrrrooo") defer func() { err = nil }() return err } func main() { fmt.Println(a()) fmt.Println(b()) }
Errorrrrrrooo Errorrrrrrooo
or
nil nil
Errorrrrrrooo nil
The text was updated successfully, but these errors were encountered:
There appears to be nothing ambiguous with the posted code.
Sorry, something went wrong.
This is expected behavior.
In a:
a
error
That returns the non-nil error.
In b:
b
That returns a nil error.
nil
We generally discourage return x when there are named return variables. Set them using = and use a bare return.
return x
=
return
Thank you for answers. I'm sorry. I found it in old good post https://blog.golang.org/defer-panic-and-recover
No branches or pull requests
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Run simple code: (https://play.golang.org/p/z2YsplDZOfp)
What did you expect to see?
or
What did you see instead?
The text was updated successfully, but these errors were encountered: