<jupyter_start><jupyter_text>User defined exceptions<jupyter_code>class CoffeeTooHotException(Exception):
    '''User defined exception to raise when coffee is too hot'''
    def __init__(self, msg):
        super().__init__(msg)
        
class CoffeeTooColdException(Exception):
    '''User defined exception to raise when coffee is too cold'''
    def __init__(self, msg):
        super().__init__(msg)
        
class CoffeeCup:
    '''Coffee cup class'''
    def __init__(self, temperature):
        self.__temperature = temperature
        
    def drinkCoffee(self):
        if self.__temperature < 65:
            raise CoffeeTooColdException(f'Coffee temperature is {self.__temperature}')
        elif self.__temperature > 85:
            raise CoffeeTooColdException(f'Coffee temperature is {self.__temperature}')
        else:
            print(f'Coffee temperature is perfect!!!')
c = CoffeeCup(75)
c.drinkCoffee()
c = CoffeeCup(100)
c.drinkCoffee()
c = CoffeeCup(10)
c.drinkCoffee()<jupyter_output><empty_output><jupyter_text>Catching user defined exceptions<jupyter_code>try:
    c = CoffeeCup(10)
    c.drinkCoffee()
except CoffeeTooHotException as e:
    print(f'Error: {str(e).capitalize()} \nType of error: {type(e)} \nDetails: {e.__doc__}')
except CoffeeTooColdException as e:
    print(f'Error: {str(e).capitalize()} \nType of error: {type(e)} \nDetails: {e.__doc__}')
else:
    print(f'Have greate Coffee!!')
finally:
    print(f'Please visit again')
try:
    c = CoffeeCup(10)
    c.drinkCoffee()
except CoffeeTooHotException as e:
    print(f'Error: {str(e).capitalize()} \nType of error: {type(e)} \nDetails: {e.__doc__}')
except CoffeeTooColdException as e:
    print(f'Error: {str(e).capitalize()} \nType of error: {type(e)} \nDetails: {e.__doc__}')
else:
    print(f'Have greate Coffee!!')
finally:
    print(f'Please visit again')<jupyter_output>Error: Coffee temperature is 10 
Type of error: <class '__main__.CoffeeTooColdException'> 
Details: User defined exception to raise when coffee is too cold
Please visit again
{'fraction_non_alphanumeric': 0.12512218963831867, 'fraction_numerical': 0.008308895405669599, 'mean_word_length': 4.130325814536341, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '32418', 'license': 'MIT', 'n_tokens_mistral': 692, 'n_tokens_neox': 656, 'n_words': 173, 'path': '04 Working with Modules and Handling Exceptions/04_user_defined_exception.ipynb', 'repo_name': 'aadhikar/python-3-basics-and-beyond', 'size': '2046'}