Skip to content
New issue

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

provide a way to return from main function with non-zero exit code and run all deferred function #42078

Closed
ghost opened this issue Oct 19, 2020 · 4 comments

Comments

@ghost
Copy link

@ghost ghost commented Oct 19, 2020

os.Exit allows to set a non-zero status code, but it exit the program immediately and no deferred functions are run.

@davecheney
Copy link
Contributor

@davecheney davecheney commented Oct 19, 2020

panic?

@ghost
Copy link
Author

@ghost ghost commented Oct 19, 2020

panic?

no.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 20, 2020

func main() {
    os.Exit(realMain())
}

func realMain() int {
    ...
    return 1
}
@mdlayher
Copy link
Member

@mdlayher mdlayher commented Oct 21, 2020

Since the author deleted their account and Ian provided an easy solution, I'm going to close this.

@mdlayher mdlayher closed this Oct 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.