Python Exception handling logic

Source: Internet
Author: User

Many of the python's functions and methods produce exceptions and are flagged as errors or important events. An exception is also an object, and when converted to a string, the exception produces a message text. The simple syntax format for exception handling is as follows:
Try :    try_suiteexcept  exception1 as variable1:    exception_suite1 ... except Exception2 as Variablen:    exception_suiten

The exception handling logic is as follows:

If the suite in the try block works without generating an exception, the except module is skipped, and if an exception is created in the try block, the control flow immediately shifts to the first suite that matches the exception---this means that Statements in the suite following the statement that generated the exception are no longer executed, and if an exception occurs, and given the as variable part, inside the exception handling suite, Variale refers to the exception object. If an exception occurs when processing a except block, or if an exception cannot match any of the except blocks, Python searches for a matching except block within the next enclosing range. The search for the appropriate exception handling module is scaled out and can be extended to the call stack until a matching exception handling module is found, or a matching module cannot be found, in which case the program terminates with an unhandled exception, and Python prints the backtracking information along with the exception's message text. Description: The above content is excerpted from the Python3 Program Development Guide. Second edition of 1.2.5.4 Festival

Python Exception handling logic

Related Article

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.