ARTS-S golang panic返回默认值

时间:2022-06-09 15:00:31
package main

import "fmt"

func fn_test_panic() (a int) {
a = 2
panic("This is panic")
return a
} func fn1() (a int) {
a = 3
defer func(){
if p := recover(); p != nil {
fmt.Println("recover")
}
}()
fmt.Println("befor call panic")
b := fn_test_panic()
fmt.Println("after call panic")
a = b
return a
}
func main() {
fmt.Println("return code:", fn1())
}