go recover

 

 

 

 

 

 

 


 

 

 

 

package main

func main() {
    defer println("defer 1")

    level1()
}

func level1() {

    defer println("defer 2")

    defer func() {
        if err := recover(); err != nil {
            println("recover 1")
        }
    }()

    defer println("defer 3")

    level2()
}

func level2() {
    defer println("defer 4")

    panic("foooo")
}

 

posted @ 2022-10-16 18:38  AngDH  阅读(43)  评论(0编辑  收藏  举报