summaryrefslogtreecommitdiff
path: root/notebooks/exception_handling.py
blob: 50bf830a8089f1bcd0239b68a701615c01fbe42c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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