go异常处理

一。defer

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

      2.

二。panic和recover

     

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")
}

 

posted on 2018-10-03 21:27  晓风残梦  阅读(102)  评论(0编辑  收藏  举报

导航