go异常处理

一。defer函数

      1. Go 语言提供了关键字 来在函数运行结束的时候运行一段代码或调用一个 清理函数spa

      2.code

二。panic和recoverblog

     

package main
import (
    "fmt"
)
func main() {
    defer func() {
       msg := recover()
       fmt.Println(msg)
    }()
    fmt.Println("I am walking and singing...")
    panic("It starts to rain cats and dogs")
}
相关文章
相关标签/搜索