exit work
This commit is contained in:
parent
66ad9b0d13
commit
ba78f8b327
@ -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
1
src/073-exit/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
exit
|
@ -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
|
||||
|
@ -9,3 +9,5 @@ $ go build exit.go
|
||||
$ ./exit
|
||||
$ echo $?
|
||||
3
|
||||
|
||||
# Note that the `!` from our program never got printed.
|
||||
|
Loading…
x
Reference in New Issue
Block a user