Python Exception Handling

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.