1.Python Exception Class
Abnormal
Describe
Nameerror
Try to access a variable that is not declared
Zerodivisionerror
Divisor is 0
SyntaxError
Syntax error
In project development, exception handling is essential. Exception handling helps people debug and, through richer information, make it easier for people to find where a bug is. Exception handling can also improve the fault tolerance of the program.
Python is an object-oriented language, so exceptions thrown by programs are also classes.
Common exception classes
1.NameError: Try to access a variable that is not declared2.ZeroDivisionError: Divisor is 03.SyntaxError: Syntax error4.IndexError:
This section focuses on the principles and main forms of exception handling in Python.
1. What is an exception
Python uses exception objects to represent exceptions. An exception is thrown when the program encounters an error during run time. If
The error message has not been described too much so far, but the error information has been used in some examples. Python has at least two types of errors:
syntax errorAnd
Exception
8.1 Syntax Errors
Syntax errors, also known as parsing errors,
1. What is an exception?An exception is an event that occurs during program execution and affects the normal execution of the program.In general, an exception occurs when Python does not handle the program properly.The exception is a Python object
You can use the Try/except statement to catch an exception.The try/except statement is used to detect errors in a try statement block, allowing the except statement to catch exception information and handle it.If you do not want to end your program
The impact of Python exceptions on code running performance.Preface
The exception handling capability of Python is very powerful, but poor use may also bring negative effects. I usually like to use exceptions when writing programs. Although it is
In a network application, this is often the case when one party tries to connect, but the other is unable to respond due to network media failure or other reasons.The Python socket library provides a way to get through the socket. The error
First, exception handlingErrors and Exceptions:1, the wrong kind:1) Syntax error: This error, the syntax of the Python interpreter cannot be detected, must be corrected before the program executes2) Logic error:Example: res1=1/0, es2=1+ ' str '2,
Markdownpad Document
Errors are divided into two types of errors in the exception handler
Syntax error: Unable to get past Python interpreter
Logic error
Exception handling what is exception handling
The Python
First: What is an exceptionAn exception is an event that occurs during program execution and affects the normal execution of the program.Different exceptions in Python can be identified in different types (Python unifies classes and types, types as
An error and an exception
Two exception handling
2.1 What is exception handling?
2.2 Why do I have to do exception handling?
2.3 How do I do exception handling?
Three when to use exception handling
Exceptions and ErrorsPart1:
10.1Throws an exception. Which of the following causes an exception to be thrown when the program executes? Note that we're not asking for exceptions here.The reason.a) users;b) interpreter;c) procedures;D) all of the above;(e) only B) and C);f)
what is an exception? Differences between exceptions and errors error syntax errors more obvious errors can be detected during the compile code phase the effect of the exception exception that is thrown when the iteration exception occurs during
Object-Oriented ProgrammingObject-oriented programming--object oriented programming, short for OOP, is a programming idea. OOP takes objects as the basic unit of a program, and an object contains functions for data and manipulating
I. Common forms of anomaliesAn exception is an event that occurs during program execution and affects the normal execution of the program. In general, an exception occurs when Python does not handle the program properly. The exception is a Python
Exception handling is essential in the development of the project. Exception handling helps people debug and make it easier for people to find out where the bug is, through richer information. Exception handling can also improve the fault tolerance
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.