mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-11-01 08:52:03 +01:00
02/02
This commit is contained in:
1 parent
15a8eaa7a5
commit
c8229eb2be
1 file changed
+33
@@ -0,0 +1,33 @@
|
|||||||
|
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)
|
||||||
Reference in new issue
Block a user