Blog: Python in the try / the except / the else / a finally Python documentation: errors and exceptions
As with other languages, in python, try / except statement is mainly used to treat a number of procedural anomalies arising in the course, such as syntax errors normal execution (python scripting language is not compiled as part of the syntax is detected in the implementation process , issued after an error exception message), data divide by zero error, such as the value of the variable has never been defined; and try / finally statements are mainly used in the case regardless of whether an exception occurs, you need to perform some cleanup work, as in communication process, regardless of whether the communication error occurs, will need to complete in a communication network connection on or off when an error occurs. Despite the different try / except and try / finally role, but in practice, generally be programmed together in combination they try / except / else finally form / to achieve stability and better design flexibility.