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