Handling errors and exceptions
There are many types of errors possible in Python. The most common one is related to the syntax of the program and is typically known as a syntax error. On many occasions, errors are reported during the execution of a program. Such errors are called runtime errors. The runtime errors that can be handled within our program are called exceptions. This section will focus on how to handle runtime errors or exceptions. Before jumping on to error handling, we will briefly introduce the most common runtime errors as follows:
IndexError
: This error occurs when a program tries to access an item at an invalid index (location in the memory).ModuleNotFoundError
: This error will be thrown when a specified module is not found at the system path.ZeroDivisionError
: This error is thrown when a program tries to divide a number by zero.KeyError
: This error occurs when a program tries to fetch a value from a dictionary using an invalid key.StopIteration...