2009-11-09 91 views

回答

32

在Python,这将是ValueError,或它的子类。

例如,试图通过.read()关闭的文件引发“ValueError:关闭文件上的I/O操作”。

9

ValueError适当的声音对我说:

Raised when a built-in operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError .

+9

不幸的是,这是指一个方法的参数,而不是对象的状态...... – 2011-04-12 07:14:52

+1

“不适当的值”足够模糊,我认为它适用于将参数传递给函数,在某些情况下可以,但由于对象的当前状态。 – 2011-04-12 12:25:38

+2

如果函数没有参数会怎么样? – 2011-05-15 22:46:38

相关问题