Python uses objects to represent abnormal abnormal state, and throws an exception if an error is encountered.
raise statement can throw an exception, or instance of a class as an argument.
>>> The raise Exception # -induced abnormalities are common, did not point out what is wrong Traceback (MOST recent Results Last Call): File " <pyshell # 120> " , Line 1, in <Module> The raise Exception Exception >>> >>> the raise Exception ( ' the hyperdrive overload ' ) # added overload error message yperdrive Traceback (MOST Recent Last Call): File " <125 pyshell #> " , Line. 1, in <Module1> the raise Exception ( 'hyperdrive overload') Exception: hyperdrive overload
Some built-in exception classes
The class name | description |
Exception | Almost all exception classes are derived from it come |
AttributeError | When referring to property caused by or assigned to it fail |
OSError | Raised when the operating system can not perform the specified tasks (such as opening a file), a number of sub-categories |
IndexError | When using initiators index sequence does not exist, for the subclass LookupError |
KeyError | When using initiators key mapping does not exist for the subclass LookupError |
NameError | Raised when a name is not found (variable) |
SyntaxError | Raised when code is incorrect |
TypeError | When the initiator or the built-in functions for the operation of the object type is incorrect |
ValueError | When the initiator or the built-in functions for operating such an object: it contains the correct type of value but unsuitable |
ZeroDivisionError | Raised when division or modulo the second parameter is zero |
to be continued......