Skip to content

Commit 15a0a39

Browse files
committed
Add exception classes
1 parent bfea45e commit 15a0a39

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

gear/gear_calc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import gear.substat as substat
22
import math
33

4+
from myexception import GearLevelException
5+
46
# Constants
57
MIN = 0
68
MAX = 1
@@ -205,4 +207,4 @@ def get_gear_level(gear_level):
205207
elif gear_level == '90':
206208
return LVL90
207209
else:
208-
print('Error gear level not supported')
210+
raise GearLevelException("Error gear level not supported")

main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cv2 as cv
22
import time
33
import pytesseract
4-
from myexception import MyException
4+
from myexception import GearParseException, GearLevelException
55
import screengrabber
66
import parser
77
from edgedetector import EdgeDetector
@@ -145,9 +145,12 @@ def __init__(self):
145145
print(curr_gear)
146146
out = curr_gear
147147

148-
except MyException as e:
148+
except GearParseException as e:
149149
details = e.args[0]
150150
out = "Error parsing gear\n" + details
151+
except GearLevelException as e:
152+
details = e.args[0]
153+
out = details
151154
except:
152155
out = "Error initialising gear"
153156

myexception.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
class MyException(Exception):
22
pass
33

4+
class GearParseException(Exception):
5+
pass
46

7+
class GearLevelException(Exception):
8+
pass

parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import gear.substat as substat
2-
from myexception import MyException
2+
from myexception import GearParseException, MyException
33

44
# trim front and back spaces, removes empty strings, parses to list format
55
def str_to_list(string):
@@ -21,7 +21,7 @@ def parse_substats(substat_name_list, substat_value_list):
2121
remove_substat_modification(substat_name_list)
2222

2323
if len(substat_name_list) != len(substat_value_list):
24-
raise MyException("number of substat names =/= number of substat values")
24+
raise GearParseException("number of substat names =/= number of substat values")
2525

2626
for i in range(len(substat_name_list)):
2727
curr_substat_name = substat_name_list[i]

0 commit comments

Comments
 (0)