将异常返回尝试块的可能性吗?

发布于 2025-01-29 14:30:19 字数 582 浏览 1 评论 0原文

我有一个愚蠢的QU。仍然任何替代解决方案都会非常有帮助。

我在源中有一个尝试块,该块调用很少的功能。

def main(self):
    try:
        dict_1 = some_fun_a(self)
        dict_2 = some_fun_b(self)
        #some operations in dict
    except KeyError:
        #Raise some exception error.

def some_fun_a(self):
    try:
        #some validation regarding original data
    except ImportError:
        #Raise Exception
        return ImportError

我可以继承func_a/b&根据REQ更改逻辑。但是,当我在这些功能中面临异常时,主要的尝试块仍然是成功的。

QUS: 无论如何,我是否可以将异常从some_fun_a()返回到main try块中,以便提出了aim()的例外?

I have a stupid qus. Still any alternate solution would be very helpful.

I have a try block in source which calls few functions.

def main(self):
    try:
        dict_1 = some_fun_a(self)
        dict_2 = some_fun_b(self)
        #some operations in dict
    except KeyError:
        #Raise some exception error.

def some_fun_a(self):
    try:
        #some validation regarding original data
    except ImportError:
        #Raise Exception
        return ImportError

I could inherit func_a/b & change logic as per req. However, when I face exception inside these functions, the main try block is still a success.

QUS:
Is there anyway I could return exception from some_fun_a() to main try block such that exception from main() is raised ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文