In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "Python capture exception example analysis", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Python capture exception example analysis" bar!
Exceptions in 1.python
Syntax error: the program is not written according to the grammar rules
Run error: run time error
Logic error: logic error
An exception object (exception object) is used to represent an exception
two。 Catch exception try-except
Exception with a divisor of 0:
Put the detected statement block into the try block and the exception handling statement block into the except block
If there is no exception in the detected statement block, the exception handling after except is ignored; otherwise, the exception handling statement block is executed.
Multiple except clauses
One except block catches multiple exceptions
Empty except: catches all exceptions
As statement:
Put the cause of the error in the err variable and print the variable
Else statement:
If there are no exceptions in the try block, the else statement is executed
If you want to type multiple times after an exception is generated until it is correct, you can add while True and break statements
The location of the break statement
Jump out of the loop if input is normal
Finally clause
Finally statements can be used in try statements, and the statement blocks in the finally clause are executed regardless of whether an exception occurs or not
Context Manager and with statements
The with statement assigns the value of the context management expression to the variable and executes its statement sequence
With automatically closes files after completion, which is the recommended usage for manipulating objects such as files and databases in python.
Thank you for your reading. The above is the content of "Python capture exception example Analysis". After the study of this article, I believe you have a deeper understanding of the problem of Python capture exception example analysis, and the specific use situation still needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.