You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
432 B

package main
import "fmt"
func funcA() {
fmt.Println("func A")
}
func funcB() {
//recover接受panic抛出的异常
//recover只能在defer函数中调用才会生效
//defer一定要在可能引发panic的语句之前定义
defer func() {
err := recover()
if err != nil {
fmt.Println("recover in B")
}
}()
panic("panic in B")
}
func funcC() {
fmt.Println("func C")
}
func main() {
funcA()
funcB()
funcC()
}