Python catch exception

Source: Internet
Author: User

Catch exceptions in Python

(try except) statement:

Try:    #把你要执行的代码放进来    ..... ... except:    #比如try上面的代码出现了异常, you'll be here    #我们可以打印一句话    print (' Error ')------------------------------------ ---------------------------, or try: #把你要执行的代码放进来    ..... Except TypeError as  reason            #类型错误         #这个参数会打印出错误的有关信息          print (' xxxx ') except ValueError as Reason               #一毛一样or: try: ... except (Xxx1error and Xxx2error):   If you do something without catching an exception, the system will error.

Whenever the code is in a try, the code in the try will not execute once an error occurs, so ... Finally The statement came out.

Finally statement:

More Insurance!!

The code can continue after the finally statement

 

Python catch exception

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.