Listing 10 - Page 0: No Title

##############################################################################
# Python From Scratch
# Autor: Nilo Ney Coutinho Menezes
# Editora Novatec (c) 2010-2024
# Site: https://pythonfromscratch.com
#
# File: listing\chapter 10\10.1471 - No Title.py
# Description: No Title
##############################################################################

class StockException(Exception):
    def __init__(self, message, error_code):
        super().__init__(message)
        self.error_code = error_code

def check_quantity(quantity):
    if quantity< 0:
        raise StockException("Negative quantity", error_code=1)

try:
    check_quantity(-10)
except StockException as ee:
    print(f"Error: {ee.error_code} {ee}")
Click here to download the file