23 lines
305 B
Go
23 lines
305 B
Go
|
|
package main
|
|||
|
|
|
|||
|
|
import "fmt"
|
|||
|
|
|
|||
|
|
func main() {
|
|||
|
|
tes()
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func tes() int {
|
|||
|
|
//利用defer+recover来捕获错误:defer加匿名函数调用
|
|||
|
|
defer func() {
|
|||
|
|
err := recover()
|
|||
|
|
if err != nil {
|
|||
|
|
fmt.Println("错误已经捕获")
|
|||
|
|
fmt.Println(err)
|
|||
|
|
}
|
|||
|
|
}()
|
|||
|
|
num02 := 10
|
|||
|
|
num01 := 0
|
|||
|
|
return num02 / num01
|
|||
|
|
}
|