What are the functions of python exception handling
This article mainly shows you "what is the role of python exception handling". It is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "what is the role of python exception handling".
1. The parser executes the program and triggers an exception when an error is detected. after the exception is triggered and is not handled, the program terminates at the current exception, and the following code will not run.
2. An exception handling mechanism must be provided to enhance the robustness and fault tolerance of your program.
Example
# coding=utf-8try: print ('- test--1---') open ('123.txtfile no longer exists) # if the 123.txt file does not exist, it will generate an IOError exception print ('-test--2---') print (num) # if the num variable is not defined Then NameError exception except (IOError,NameError): # if you want to catch more than one exception through an except, you can use a tuple to print ("catch exception"). This is all the content of the article "what is the purpose of python exception handling?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!