Skip to content

Instantly share code, notes, and snippets.

@liuliqiang
Last active August 15, 2018 15:41
Show Gist options
  • Save liuliqiang/689ec311ffc6264aaf9ac83b9a738dbb to your computer and use it in GitHub Desktop.
Save liuliqiang/689ec311ffc6264aaf9ac83b9a738dbb to your computer and use it in GitHub Desktop.
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