Python try/except/else/finally Execution order

Source: Internet
Author: User

The full format of the try/except/else/finally statement in Python:

1 Try:2 Normal Block3 exceptA:4 Exception A Handle5 except:6 Other exception handle7 Else:8      Print "Else"9 finally:Ten      Print("finally")
1, normal condition (Try statement block execution no exception occurred): Execution order: statement block in 1.1 try, 1.2Else statement block, 1.3 finally statement block 2, exception (try statement execution exception): Execution order: 2.1 Executes a try statement, an exception occurs, interrupts the execution of a try statement block, 2.2 starts at the first except, if the corresponding Cxcepti is found On, the corresponding processing branch is entered and processed.    If the individual except are not found, enter the default except branch. 2.3 Execute FINALLY statement block NOTE: Do not execute the ELSE statement block at this time 3.1 try must be executed, finally is to be executed 3.2 else and finally is optional, if else is selected, then must have except 3.3 have try, at least A except

Python try/except/else/finally Execution order

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.