Get the App
SLTechnology News&Howtos  ›  Development  › 

An example introduction of catching exception by python

Shulou Source: shulou.com Published: 2022-06-03 15:15:57 10月03日 Update

This article mainly explains the "example introduction of python catch exception", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "python catch exception example introduction"!

1. Exception capture is code that may go wrong in a certain part. Once an error occurs during the run, the misinformation is written to the log file or other processing, and then continues to run the subsequent code.

2. The purpose of catching exceptions is to prevent the code from stopping running.

Example

In program development, if the execution of some code is uncertain (the syntax of the program is completely correct), you can add try to catch the exception try: the code you are trying to execute except: the handling of the error try: num = int ("Please enter an integer:") except: print 'Please enter the correct integer!' # No matter whether the input is abnormal or not, it will output print'@'* 50 normally. Thank you for your reading. The above is the content of "introduction of examples of python catching exceptions". After the study of this article, I believe you have a deeper understanding of the introduction of examples of python catching exceptions, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Examples code learning input running content integers programs errors processing that is ideas situations files articles logs more purpose knowledge knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Technology macOS Linux Shulou Tech Info