Computers are so popular because of one reason, it doesn't make mistakes however programmers make mistakes therefore every programmer should know how to handle errors. Some error can be prevented if programmer can predict problems but most times an application fails because of excepted actions done by users and natural causes. Python have three simple statements to handle errors.
Try block: lets you test a block of code for errors.
Except block: lets you handle the error.
Finally block: lets you execute code, regardless of the result of the try- and except blocks.
Syntax:
try: # Some Code.... except: # optional block # Handling of all exception (if required) except NameError: # optional block # Handling of exception according to error else: # execute if no exception finally: # Some code .....(always executed)