Last active
March 4, 2017 14:56
-
-
Save xavierskip/8fc8526ec3af545d30de130020d0bc8a to your computer and use it in GitHub Desktop.
gopl.io 5.19 使用panic和recover编写一个不包含return语句但能返回一个非零值的函数
This file contains hidden or 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
func noReturn() (result int) { | |
defer func() { | |
p := recover() | |
result = p.(int) | |
}() | |
panic(42) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment