summaryrefslogtreecommitdiff
path: root/py02/ex2/ft_different_errors.py
diff options
context:
space:
mode:
authoryctct <yctct@yctct.com>2026-06-07 08:59:04 +0200
committeryctct <yctct@yctct.com>2026-06-07 08:59:04 +0200
commit15115b4c52bfda0d1cca9fa1155beecbb873ec35 (patch)
treeb3f0975e63eb04dcba732a78ce9bd9abda8acf01 /py02/ex2/ft_different_errors.py
First commit, add all files
Diffstat (limited to 'py02/ex2/ft_different_errors.py')
-rwxr-xr-xpy02/ex2/ft_different_errors.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/py02/ex2/ft_different_errors.py b/py02/ex2/ft_different_errors.py
new file mode 100755
index 0000000..cd64d5f
--- /dev/null
+++ b/py02/ex2/ft_different_errors.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python3
+# https://docs.python.org/3/tutorial/errors.html#handling-exceptions
+
+def garden_operation(operation_number):
+ if operation_number == 0:
+ int("abc")
+ elif operation_number == 1:
+ 10 / 0
+ elif operation_number == 2:
+ open("/file.txt")
+ elif operation_number == 3:
+ "string" + 3
+ else:
+ print("Operation completed successfully")
+
+
+def test_error_types():
+ print("=== Garden Type Demo ===")
+ for i in range(5):
+ try:
+ print(f"Testing operation {i} ...")
+ garden_operation(i)
+ except ValueError as err:
+ print("Caught ValueError", err)
+ except ZeroDivisionError as err:
+ print("Caught ZeroDivisionError:", err)
+ except FileNotFoundError as err:
+ print("Caught FileNotFoundError:", err)
+ except TypeError as err:
+ print("Caught TypeError:", err)
+ print()
+ return print("All error types tested successfully!")
+
+
+if __name__ == "__main__":
+ test_error_types()