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 { type Shape interface {
area() float64 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 // ## Exit
package main
// Use `os.Exit` to immediatly exit with a given // Use `os.Exit` to immediatly exit with a given
// status. // status.
package main
import "os" import "os"
func main() { func main() {
// This `println` will never be reached because the // `defer`s will _not_ be run when using `os.Exit`, so
// exit is immediate. // this `println` will never be called.
defer println("!") defer println("!")
// Exit with status 3.
os.Exit(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 // todo: discuss building before getting here

View File

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