This commit is contained in:
Mark McGranaghan 2012-09-16 14:21:14 -07:00
parent 091df794a3
commit 8a6928e2ce
5 changed files with 61 additions and 0 deletions

16
25-defer.go Normal file
View File

@ -0,0 +1,16 @@
package main
import "fmt"
func first() {
fmt.Println("1st")
}
func second() {
fmt.Println("2nd")
}
func main() {
defer second()
first()
}

8
26-panic.go Normal file
View File

@ -0,0 +1,8 @@
package main
import "fmt"
func main() {
panic("O noes")
fmt.Println("Finished")
}

10
27-recover.go Normal file
View File

@ -0,0 +1,10 @@
package main
import "fmt"
func main() {
defer func() {
fmt.Println("Preparing for trouble...\n")
}()
panic("Trouble!")
}

13
28-values.go Normal file
View File

@ -0,0 +1,13 @@
package main
import "fmt"
func zero(x int) {
x = 0
}
func main() {
x := 5
zero(x)
fmt.Println(x)
}

14
29-pointers.go Normal file
View File

@ -0,0 +1,14 @@
package main
import "fmt"
func zero(xPtr *int) {
*xPtr = 0
}
func main() {
x := 5
fmt.Println(x)
zero(&x)
fmt.Println(x)
}