本文介绍了检查恐慌而无法恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在defer函数中,我想查看一次恢复调用是否会产生非零值(不恢复)

In a defer function, I want to see whether a call to recover would yield a non-nil value (without recovering)

有可能吗?

推荐答案

那不可能。您可能只是想重新恐慌,就像在其他语言中重新引发异常一样;

That exact thing isn't possible. You probably just want to re-panic, basically like re-throwing an exception in other languages;

        defer func() {
             if e := recover(); e != nil {
                 //log and so other stuff
                 panic(e)
             }
          }()

这篇关于检查恐慌而无法恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 09:12