Skip to content

Latest commit

 

History

History
18 lines (15 loc) · 534 Bytes

custom_exceptions.md

File metadata and controls

18 lines (15 loc) · 534 Bytes

Custom Exceptions

Purpose

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.

How-To Basics

  1. Extend the Exception class
  2. Override necessary methods

Example

class MyCustomException(Exception):
    def __init__(self, custom_param):
        self.custom_param = custom_param
        super().__init__('MyCustomException occurred')