diff options
author | Zhongheng Liu <z.liu@outlook.com.gr> | 2025-03-11 15:25:56 +0200 |
---|---|---|
committer | Zhongheng Liu <z.liu@outlook.com.gr> | 2025-03-11 15:25:56 +0200 |
commit | 0e6d874c4abb734a915f719f0a507724c7a754fa (patch) | |
tree | 03c1d24cba09bc2d1216f45e930c2d877e269a7b /notebooks/exception_handling.py | |
parent | 9568147aefac22f8928460220560c62bbd972c99 (diff) | |
download | cs-y13-0e6d874c4abb734a915f719f0a507724c7a754fa.tar.gz cs-y13-0e6d874c4abb734a915f719f0a507724c7a754fa.tar.bz2 cs-y13-0e6d874c4abb734a915f719f0a507724c7a754fa.zip |
feat: add ESQs
Diffstat (limited to 'notebooks/exception_handling.py')
-rw-r--r-- | notebooks/exception_handling.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/notebooks/exception_handling.py b/notebooks/exception_handling.py new file mode 100644 index 0000000..50bf830 --- /dev/null +++ b/notebooks/exception_handling.py @@ -0,0 +1,34 @@ +# Exception handling +# - programming errors +# - user errors +# TRY +# <statement> +# EXCEPT +# <statement> +# ENDTRY + +def safe_student_open(filename): + try: + sfile = open(filename, 'rb') + sfile.close() + except OSError: + print("wtf is this file man") + +def test_input_integer(): + val = input("sample input: ") + try: + value = int(val) + print(value) + print("It is an integer") + except ValueError: + print("Noooo bro it isn't an integer cmon man get good") +# test_input_integer() + +def integer(num): + try: + b = int(num) + print(b) + print("is integer") + except: + print("not") +safe_student_open("thing.data")p
\ No newline at end of file |