exit work

This commit is contained in:
Mark McGranaghan 2012-10-03 09:55:25 -07:00
parent 66ad9b0d13
commit ba78f8b327
4 changed files with 18 additions and 5 deletions

View File

@ -7,3 +7,5 @@ import "fmt"
type Shape interface {
area() float64
}
// todo: that great blog post on interfaces

1
src/073-exit/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
exit

View File

@ -1,16 +1,24 @@
// Exit
package main
// ## Exit
// Use `os.Exit` to immediatly exit with a given
// status.
package main
import "os"
func main() {
// This `println` will never be reached because the
// exit is immediate.
// `defer`s will _not_ be run when using `os.Exit`, so
// this `println` will never be called.
defer println("!")
// Exit with status 3.
os.Exit(3)
}
// Note that unlike e.g. C, Go does not use an integer
// return value from `main` to indicate exit status. If
// you'd like to exit with a non-zero status you should
// use `os.Exit`.
// todo: discuss building before getting here

View File

@ -9,3 +9,5 @@ $ go build exit.go
$ ./exit
$ echo $?
3
# Note that the `!` from our program never got printed.