Syntax for exception:
Types of exceptions:
|
nameerror |
Try to access an undeclared variable, such as I did not define the variable a and then I go to access this variable and the exception appears |
|
importerror |
cannot introduce a module or package, no module or module path does not exist |
|
Indentationerror |
indentation error, code not correctly aligned |
|
syntaxerror |
syntax error |
|
indexerror |
index out of sequence range |
|
keyerror |
Request a non-existent dictionary keyword (that is, there is no access to the key ) |
|
ioerror |
input/output error (e.g. the file you want to read does not exist) |
|
attributeerror |
Try to access unknown object properties, such as I use os.abc prompt error |
|
valueerror |
int () function passed in string type |
|
Unboundlocalerror |
Try to access a local variable that has not yet been set, such as I have defined the variable outside the function; a a This exception occurs with the addition operation, and the detailed usage is |
|
Keyboardinterrupt |
keyboard interrupt operation, such as pressing ctrl + C |
|
Exception |
This exception can be written in the script if you do not know what will happen |
Python Exception Handling