go-defer用例
package main
import (
"fmt"
)
func main() {
a := 1
b := 2
defer func() {
err := recover() //recover只能放在defer之后使用
fmt.Println(err)
}() //匿名函数
swap(a, b)
}
func swap(a, b int) {
a, b = b, a
fmt.Println(a, b)
panic("panic is wrong")
}