Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 引发异常或引发异常()_Python_Exception_Exception Handling - Fatal编程技术网

Python 引发异常或引发异常()

Python 引发异常或引发异常(),python,exception,exception-handling,Python,Exception,Exception Handling,我需要提出一个例外。在我的特定情况下,未实现错误。 两者的区别是什么 raisenotimplementederror和raisenotimplementederror() 哪一种被认为是更好的做法?为什么?在raisex和raisex()之间没有区别。最好使用第二种形式并传递一条消息,如raiseruntimeerror('bad argument')。如果没有像您这样有用的消息,我将使用第一种语法。这是品味的问题 第一种形式是旧式提升的剩余形式(在Python3中无效): 与 raise X

我需要提出一个例外。在我的特定情况下,
未实现错误
。 两者的区别是什么
raisenotimplementederror
raisenotimplementederror()


哪一种被认为是更好的做法?为什么?

raisex
raisex()
之间没有区别。最好使用第二种形式并传递一条消息,如
raiseruntimeerror('bad argument')
。如果没有像您这样有用的消息,我将使用第一种语法。这是品味的问题

第一种形式是旧式提升的剩余形式(在Python3中无效):

raise X('a')
raise X('a')