abnormal
- In order to be a more robust program, errors encountered in the program may appear to be as far as possible be resolved. For possible errors handling code is exception handling.
- A piece of code, if an exception is encountered, do not get treatment, the entire program will be stopped , if processed, the program runs down.
Simple exception handling, try-except:
Formats such as:
the try: # try to catch the exception code (code may be wrong) : the except code # abnormality to be executed
Abnormal capture the complete syntax:
In the actual development, a section of code might encounter different errors, there are different approaches for different error, then we need to deal with the following format:
the try: # trying to capture abnormal code (may be wrong code) the except Error Type 1: # emerge Code Error type after 1 to be performed except (Error type 1, Error type 2): # Error type after 1 and 2 to code that executes the except exception AS the Result: # emerge other type of error code to be executed (usually told that an unknown error)
the else:
# no code will be executed abnormal
Pass
a finally:
# code that regardless of whether there is an exception, to be executed