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