【发布时间】:2019-12-26 02:31:38
【问题描述】:
我见过有人同时做这两种方式,但我看不出它们之间的区别:
raise Exception('This is the error')
和
raise 'This is the error'
我应该使用哪一个?
【问题讨论】:
-
raise 'This is the error'那行不通。你在哪里看到的? -
raise Exception 'This is the error'这也不行。也许你的意思是raise Exception('This is the error')? -
很久很久以前,人们可以提出任何价值作为例外,但我认为“特性”在 Python 2.0 中被消除了。
-
非常老的 Python 版本中的
raise语句与现在完全不同;例如,见docs.python.org/release/1.5.2p2/ref/raise.html。
标签: python python-3.x exception try-catch