diff --git a/learning/06-error-handling/errors.py b/learning/06-error-handling/errors.py new file mode 100644 index 0000000..cc22e2c --- /dev/null +++ b/learning/06-error-handling/errors.py @@ -0,0 +1,20 @@ +#import os + +def safe_divide(a, b): + try: + return a / b + except ZeroDivisionError: + return("i can't do that dave") +def safe_read(fn): + try: + f = open(fn) + contents = f.read() + f.close() + return contents + except FileNotFoundError: + return "there is no spoon" + +result =safe_divide(100, 10) +print(result) +print(safe_read("errors.py")) +print(safe_read("nonexistent.txt")) \ No newline at end of file