-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_exceptions.py
More file actions
37 lines (30 loc) · 764 Bytes
/
user_exceptions.py
File metadata and controls
37 lines (30 loc) · 764 Bytes
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
35
36
37
#/bin/python
# Python program for playing around with user defined exceptions
class TooSmallError(Exception):
message = "Too small! Try again ;)"
class TooBigError(Exception):
message = "Too big! Try again ;)"
class ExactError(Exception):
def __init__(self):
print "HAHAHA You hit the trap"
class unhandledError(Exception):pass
def checkNumber(num):
if(num <= 4):
raise TooSmallError
elif(num >= 7):
raise TooBigError
elif(num == 5):
raise ExactError
return num
while 1:
try:
usrInpt = int(raw_input("Enter the magic number: "))
print checkNumber(usrInpt)
except TooSmallError, e:
print e.message
except TooBigError, e:
print e.message
except ExactError, e:
print e.message
else:
break