【发布时间】:2021-11-24 03:52:26
【问题描述】:
看看这个:
RuntimeError: No active exception to reraise
我使用raise。没有这样的错误:
class example:
def __getattribute__(self, attr_name):
raise # I mean: AttributeError: '...' object has no attribute '...'
raise_stmt ::= "raise" [expression ["from" expression]]
表达式是可选的。
我查看this,但这不是我的答案。如果错误显示“没有要重新引发的活动异常”,那么我可以激活错误。我不知道这个错误是什么意思。我的问题是,“主动异常”是什么意思,在哪里使用?它是否有助于使代码更短、更优化?是否可以将它用于我在代码中显示的稍高一点的任务?
【问题讨论】:
-
这能回答你的问题吗? raise with no argument
-
这是一个很接近的问题,但我的问题还有其他目的
-
你能澄清你的问题吗?一个裸露的
raise"re-raises the last exception that was active in the current scope"。您的代码中没有任何活动异常,这正是错误所说的。 -
我需要属性
AttributeError: '...' object has no attribute '...'的默认错误 -
不存在默认错误。你提到的
AttributeError是由一些代码主动提出的——如果你不调用它,Python 无法知道你指的是哪个错误。
标签: python python-3.x exception