Python Learning notes-exceptions

Source: Internet
Author: User

Python run-time errors are called exceptions

    1. Syntax error : The software is structurally faulty and cannot be interpreted by the interpreter or compiled by the compiler.

2. Logic error : Due to incomplete or illegal input, it may be that the logic can not survive, the calculation or the output of the required process can not be executed and so on.


A Python exception is an object that represents an error or unexpected condition

An exception is triggered when Python detects an error

1.python can pass an anomaly through an abnormal conduction mechanism, emitting a signal that an abnormal condition occurs.

2. Programmers can also manually trigger exceptions in the code


python Exceptions can also be understood as: behavior that occurs when a program has errors and is taken outside of the normal control flow

First stage: The interpreter triggers an exception, at which time the current flow of the program is interrupted

Phase two: exception handling, such as ignoring non-fatal errors, mitigating the effects of errors, etc.


The function of the anomaly

  Error handling:

default processing for Python: Stop programs, print error messages

Handling exceptions and recovering from exceptions using a try statement

Event Notification:

Used to emit a valid status signal

Special case Processing:

Unable to adjust the code to handle the scene

termination Behavior:

The try/finally statement ensures that the necessary end-handling mechanism is performed

Unconventional control processes:

An exception is an advanced jump (goto) mechanism


Detecting and Handling exceptions

Exceptions are detected by a try statement

any code in a try statement block will be detected to detect the occurrence of an exception     

There are two main forms of a try statement:

try-except: Detecting and Handling exceptions

can have multiple except

Support for using the ELSE clause to handle code for execution without probing exceptions

try-finally: Check for exceptions only and do some cleanup work as necessary

Compound form of Try statement

try-except-finally


This article is from the "Shei" blog, make sure to keep this source http://kurolz.blog.51cto.com/11433546/1935031

Python Learning notes-exceptions

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.