mirror of
https://github.com/DavidGailleton/42-Piscine_Python.git
synced 2026-03-14 05:06:55 +01:00
FIX: every exercices of module 02
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
def garden_operations(case: str) -> None:
|
||||
"""Test some opereation case"""
|
||||
if case == "ValueError":
|
||||
int("abc")
|
||||
elif case == "ZeroDivisionError":
|
||||
@@ -11,26 +12,29 @@ def garden_operations(case: str) -> None:
|
||||
|
||||
|
||||
def test_error_types() -> None:
|
||||
"""Tester function to catch errors"""
|
||||
print("=== Garden Error Types Demo ===")
|
||||
print("\nTesting ValueError...")
|
||||
try:
|
||||
garden_operations("ValueError")
|
||||
except ValueError:
|
||||
print("Caught ValueError: invalid literal for int()")
|
||||
|
||||
print("\nTesting ZeroDivisionError...")
|
||||
try:
|
||||
garden_operations("ZeroDivisionError")
|
||||
except ZeroDivisionError:
|
||||
print("Caught ZeroDivisionError: division by zero")
|
||||
|
||||
print("\nTesting FileNotFoundError...")
|
||||
try:
|
||||
garden_operations("FileNotFoundError")
|
||||
except FileNotFoundError as err:
|
||||
print("Caught FileNotFoundError:", err)
|
||||
|
||||
print("\nTesting KeyError...")
|
||||
try:
|
||||
garden_operations("KeyError")
|
||||
except KeyError as err:
|
||||
print("Caught KeyError:", err)
|
||||
|
||||
print("\nTesting multiple errors together...")
|
||||
try:
|
||||
garden_operations("ValueError")
|
||||
except (ValueError, KeyError, ZeroDivisionError, FileNotFoundError):
|
||||
@@ -39,4 +43,4 @@ def test_error_types() -> None:
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_error_types()
|
||||
print("All error types tested successfully!")
|
||||
print("\nAll error types tested successfully!")
|
||||
|
||||
Reference in New Issue
Block a user