--
What's wrong with just calling os.Exit with a nonzero code when you have a failure in main?
Am 20.12.2012 23:29 schrieb "Kyle Lemons" <kev...@google.com>:
>
> What's wrong with just calling os.Exit with a nonzero code when you have a failure in main?
>
deferred calls will not fire
I see the pattern / bigger underlying 'issue'. That might be the reason why there is no atexit too. Thinking about it I can't propose a better solution either.
I find myself rather often write
func main() {
os.Exit(mymain())
}
func main() {
var exit int // or exit := 0
defer os.Exit(exit)// do whatever you want and set exit}
Sorry. Of course, this won't work, because the arguments are evaluated when you call defer.However, a function which takes a pointer may be useful:
func exit(e *int) {
os.Exit(*e)
}