附录:Go语言简析¶
os.Exit¶
在 http://golang.org/pkg/os/#Exit 我们可以看到
func Exit(code int)
Exit causes the current program to exit with the given status code. Conventionally, code zero indicates success, non-zero an error. The program terminates immediately; deferred functions are not run.
实际运行时,发现如果 code != 0,会输出信息:exit status n
现在,问题出来了 :
- 如果我想 os.Exit(3) 但是不想看到那一句信息 “exit status 3”,有办法吗?
- 如果我想体面地退出当前程序,把 deferred 函数都运行后再退出,有办法吗?
答案是 no 。 没有办法。
从这个简单的例子,就可以看出,Go 语言是一个不完备的语言。不建议把 Go 语言作为主开发语言。
慎之