Last active
August 15, 2018 15:41
-
-
Save liuliqiang/689ec311ffc6264aaf9ac83b9a738dbb to your computer and use it in GitHub Desktop.
Go 语言中的异常处理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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