Reprinted from Https://www.cnblogs.com/JohnABC/p/4065437.htmlLearning Python or other programming languages with abnormal control , it is very possible to say that the execution of try except finally (try Catch finally) is very simple, nothing but
As in other languages, in Python, thetry/except statement is primarily used to handle some exceptions that occur during normal execution of a program , such as syntax errors (Python is not compiled as a scripting language, and syntax is detected
The use of try...except...finally in PythonAuthor:headsen Chendate:2018-04-09 16:22:11Try, except, finally is the exception-catching mechanism in python, and the usual usage is try: Except ... In combination, the program captures the exception in
Learned about Python's error handling today.In the process of program processing, there are often errors, once the error is very troublesome. So some high-level languages are usually built into a set of try...exept...finaly ... Error-handling
Illustrate the use of try/except/finally.If you do not use try/except/finally1 ' ABC ' 2 def fetcher (obj, index): 3 return Obj[index] 4 5 fetcher (x, 4)Output: " test.py " in 4) "test.py" in fetcher return obj[index]indexerror:string
try//attempt to execute{Somecode}except//execution When an error occurs, except has a specific type of error{Somecode}Endtry//attempt to execute{Somecode}finally//is enforced anyway.{Somecode}EndCases:TryAge:=strtoint (Edit1.text);ShowMessage
try//attempt to execute{Somecode}except//execution When an error occurs, except has a specific type of error{Somecode}Endtry//attempt to execute{Somecode}finally//is enforced anyway.{Somecode}EndCases:TryAge:=strtoint (Edit1.text);ShowMessage
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.