Sometimes we as developers need to create our own custom exceptions to add on to the built-in
exceptions that Python provides for us. For example, we may want to continue
a for loop if we
catch a specific exception.
- Extend the
Exception
class - Override necessary methods
class MyCustomException(Exception):
def __init__(self, custom_param):
self.custom_param = custom_param
super().__init__('MyCustomException occurred')