处理恐慌和延迟函数

huangapple go评论138阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2012年1月10日 22:58:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/8805322.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定