more
This commit is contained in:
parent
091df794a3
commit
8a6928e2ce
16
25-defer.go
Normal file
16
25-defer.go
Normal 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
8
26-panic.go
Normal file
@ -0,0 +1,8 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
panic("O noes")
|
||||
fmt.Println("Finished")
|
||||
}
|
10
27-recover.go
Normal file
10
27-recover.go
Normal 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
13
28-values.go
Normal 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
14
29-pointers.go
Normal 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)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user