Files
42-Piscine_Python/02/ex2/ft_custom_errors.py
David Gailleton c8229eb2be 02/02
2025-12-24 13:49:38 +00:00

34 lines
787 B
Python

class GardenError(Exception):
def __init__(self, message):
self.message = message
def __str__(self):
return f"Caught a garden error: {self.message}"
class PlantError(GardenError):
def __init__(self, message):
self.message = message
def __str__(self):
return f"Caught PlantError: {self.message}"
class WaterError(GardenError):
def __init__(self, message):
self.message = message
def __str__(self):
return f"Caught WaterError: {self.message}"
if __name__ == "__main__":
try:
raise PlantError("The tomato plant is wilting!")
except PlantError as err:
print(err)
try:
raise WaterError("Not enough water in the tank!")
except WaterError as err:
print(err)