Skip to content

Instantly share code, notes, and snippets.

@liuliqiang liuliqiang/defer顺序
Last active Aug 15, 2018

Embed
What would you like to do?
Go 语言中的异常处理
package main
import "fmt"
func main() {
defer func() {
fmt.Println("stack a")
}()
defer func() {
fmt.Println("stack b")
if err := recover(); err != nil {
fmt.Println(err)
}
}()
panic("fault")
}
// created by https://liqiang.io
try {
fmt.Println("main")
panic("fault")
} catch Exception {
fmt.Println("stack b")
fmt.Println(err)
} finally {
fmt.Println("stack a")
}
package main
import "fmt"
func main() {
defer func() {
fmt.Println("stack a")
}()
defer func() {
fmt.Println("stack b")
if err := recover(); err != nil {
panic(err)
}
}()
panic("fault")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.