#!/usr/bin/env python3 class GardenError(Exception): def __init__(self, message="Unknown plant error"): self.message = message # Why self.message; why not just 'message' super().__init__(self.message) class PlantError(GardenError): pass class WaterError(GardenError): pass def test_plant_error(veg_item): if veg_item not in veg_list: raise PlantError(f"The {veg_item} is not in the list!") else: print("The vegetale is in the list") def test_water_error(level): if level < 10: raise WaterError("Not enough water in the tank!") else: print("We have enough water!") def main(): print("== Custom Garden Errors Demo") print() try: print("Testing PlantError...") test_plant_error("spinach") except PlantError as err: print("Caught PlantError:", err) print() try: print("Testing WaterError...") test_water_error(4) except WaterError as err: print("Caught WaterError:", err) try: print() print("Testing catching all garden errors...") test_plant_error("spinach") except GardenError as err: print("Caught GardenError:", err) try: test_water_error(4) except GardenError as err: print("Caught GardenError:", err) finally: print() print("All custom error types work correctly!") if __name__ == "__main__": veg_list = ["carrot", "fennel", "sesame"] main()