golang Panic after defer?


本文摘自网络,作者,侵删。

原文链接:https://blog.golang.org/defer-panic-and-recover
Panic is a built-in function that stops the ordinary flow of control and begins panicking. When the function F calls panic, execution of F stops, any deferred functions in F are executed normally, and then F returns to its caller. To the caller, F then behaves like a call to panic. The process continues up the stack until all functions in the current goroutine have returned, at which point the program crashes. Panics can be initiated by invoking panic directly. They can also be caused by runtime errors, such as out-of-bounds array accesses.

Panic是一个内置函数,可停止常规控制流并开始恐慌。当函数F调用恐慌时,F的执行停止,F中任何延迟的函数都将正常执行,然后F返回其调用方。对于呼叫者,F然后表现得像是发生了恐慌。该过程将继续执行堆栈,直到返回当前goroutine中的所有函数为止,此时程序崩溃。紧急事件可以通过直接调用紧急事件来启动。它们也可能是由运行时错误引起的,例如越界数组访问。

Recover is a built-in function that regains control of a panicking goroutine. Recover is only useful inside deferred functions. During normal execution, a call to recover will return nil and have no other effect. If the current goroutine is panicking, a call to recover will capture the value given to panicbai'du and resume normal execution.

恢复是一个内置函数,可以重新获得对紧急恐慌例程的控制。恢复仅在延迟函数内部有用。在正常执行期间,恢复调用将返回nil并且没有其他效果。如果当前goroutine处于恐慌状态,则调用restore会捕获提供给panic的值并恢复正常执行。


本文来自:简书

感谢作者:哆啦在这A梦在哪

查看原文:golang Panic after defer?

相关阅读 >>

[Go] Golang happen before 的保证原则

手撸Golang Go与微服务 saga模式之7

手撸Golang 仿spring ioc/aop 之3

Go 语言中的一些非常规优化

Golang主要开发什么?

erlang和Golang的区别

Golang怎么编写一个window定时关机

聊聊dubbo-Go-proxy的timeoutfilter

Golang变量的数据类型

手撸Golang Go与微服务 saga模式之9 小结/gitee源码

更多相关阅读请进入《Go》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...