英文:
Handling panic and deferred func
问题
首先,我喜欢Go语言:D 我有一些关于panic/recover的问题。panic只能在延迟函数中恢复吗?当发生死锁时,延迟函数会被调用吗?我已经测试过了,但是没有...你能解释一下为什么不会被调用吗?
英文:
First of all I love GO I have some questions about panic/recover. Panic can be recovered only in deferred funcs? Is deferred func called when deadlock happens? I have tested it and no... Can you please explain why not?
答案1
得分: 1
是的,只能在延迟函数中恢复恐慌。
是的,只能在延迟函数中恢复恐慌。
这是Go运行时作者做出的一种实现选择。假设从死锁中恢复是几乎不可能的。
英文:
> Panic can be recovered only in deferred funcs?
Yes, only in deferred funcs.
> Is deferred func called when deadlock happens? I have tested it and no... Can you please explain why not?
It is an implementation choice made by the authors of the Go run-time. The assumption is that recovering from a deadlock is practically impossible.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论