代码拉取完成,页面将自动刷新
package main
// Go makes it possible to recover from a panic, by using the
// recover built-in function. A recover can stop a panic from
// aborting the program and let it continue with execution instead.
// An example of where this can be useful: a server wouldn't want to
// crash if one of the client connections exhibits a critical error.
// Instead, the server would want to close that connection and continue
// serving other clients. In fact, this is what Go's net/http does
// by default for HTTP servers.
import "fmt"
// This function panics.
func mayPanic() {
panic("a problem")
}
func main() {
// recover must be called within a deferred function. When the
// enclosing function panics, the defer will activate and a
// recover call within it will catch the panic.
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered. Error:\n", r)
}
}()
mayPanic()
// This code will not run, because mayPanic() panics.
// The execution of main stops at the point of the panic and
// resumes in the deferred closure.
fmt.Println("After mayPanic()")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。