When we enter the wrong code, Python will throw errors and exceptions. This causes the program to abruptly stop. In Python, there is exception handling available using try-except option in data science. Error can be there using the exception class.
Creating user defined exception:
We can only derive exceptions from exception class. It can be direct or indirect. So, to create our own exception, we should first create an exception class. In Python, most of the exceptions end with Error. Although not necessary, it is a custom in the Python world.
Knowing about Exception Class:
In order to get information about class Exception, we have a code which is given below.
Deriving Error from Super Class Exceptions:
When a module has to handle several distinct errors, we need to create superclass exception. We can do it through creating a base class for exceptions defined through the required module. Various sub-classes have to be defined in order to create specific exception classes for different error conditions.
Using Standard Exceptions as Base Class:
When a generator fails to fall into any category, then, Runtime Error is raised. In the program below, we will understand to use runtime error as base class and network error as derived class. We can derive any exception from the standard exception of Python.