@@ -73,15 +73,144 @@ class Unspecified(Error):
7373 Represents a unspecified error.
7474 """
7575
76- def __init__ (self , description : str , line : int = 0 , column : int = 0 ) -> None :
76+ def __init__ (self , description : str , line : int = 0 , column : int = 0 , exit_code = 2 ) -> None :
7777 """Initialize a new unspecified error.
78-
7978 :param description: Description of the error.
8079 :param line: Line the error occurred on.
8180 :param column: Column the error occurred on.
8281 """
8382
84- super ().__init__ (description , line , column )
83+ super ().__init__ (text = description , line = line , column = column , exit_code = exit_code )
84+
85+ class UnknownError (Error ):
86+ def __init__ (self , line : int , column : int ):
87+ super ().__init__ (description = "Don't you dare trying to break this stuff" , line = line , column = column )
88+
89+
90+ class SyntaxError (Error ):
91+ def __init__ (self , line : int , column : int , text = "Syntax Error" , hint : str = "" , exit_code = 3 ):
92+ if hint : print (hint )
93+ super ().__init__ (text = text , line = line , column = column , exit_code = exit_code )
94+
95+
96+ class TypeError (SyntaxError ):
97+ def __init__ (self , line : int , column : int , type_expected , type_got , text = "Type Error" , exit_code = 4 ):
98+ hint = f"expected { type_expected } got { type_got } "
99+ super ().__init__ (text = text , line = line , column = column , exit_code = exit_code , hint = hint )
100+
101+
102+ class InvalidAssignmentError (TypeError ):
103+ def __init__ (self , line : int , column : int , type_expected , type_got ):
104+ super ().__init__ (line = line , column = column , text = "Invalid Assignment" , exit_code = 5 , type_expected = type_expected , type_got = type_got )
105+
106+
107+ class EmptyAssignmentError (TypeError ):
108+ def __init__ (self , line : int , column : int , type_expected ):
109+ super ().__init__ (line = line , column = column , text = "Empty Assignment" , exit_code = 6 , type_expected = type_expected , type_got = None )
110+
111+
112+ class UnclosedError (SyntaxError ):
113+ def __init__ (self , line : int , column : int , delimiter : str ):
114+ super ().__init__ (line = line , column = column , exit_code = 7 , hint = f"Expected: { delimiter } " )
115+
116+
117+ class RuntimeError (Error ):
118+ def __init__ (self , line : int , column : int , exit_code = 8 , text = "Runtime Error" ):
119+ super ().__init__ (text = text , line = line , column = column , exit_code = exit_code )
120+
121+
122+ class PythonError (RuntimeError ):
123+ def __init__ (self , line : int , column : int , python_error : BaseException ):
124+ print (python_error )
125+ super ().__init__ (text = "Python Error" , line = line , column = column , exit_code = 9 )
126+
127+
128+ class EncodingError (Error ):
129+ def __init__ (self , line : int , column : int , text = "Encoding Error" ):
130+ super ().__init__ (text = text , line = line , column = column , exit_code = 10 )
131+
132+
133+ class ValueError (Error ):
134+ def __init__ (self , line : int , column : int , obj , function_name : str ):
135+ print (f"invalid argument { obj } for function { function_name } " )
136+ super ().__init__ (text = "Value Error" , line = line , column = column , exit_code = 11 )
137+
138+
139+ class MemoryError (RuntimeError ):
140+ def __init__ (self , line : int , column : int , exit_code = 12 , hint : str = "" , text = "Memory Error" ):
141+ if hint : print (hint )
142+ super ().__init__ (text = text , line = line , column = column , exit_code = exit_code )
143+
144+
145+ class NameError (MemoryError ):
146+ def __init__ (self , line : int , column : int , name : str ):
147+ hint = f"name { name } is not defined"
148+ super ().__init__ (text = "Name Error" , line = line , column = column , exit_code = 13 , hint = hint )
149+
150+
151+ class KeyError (MemoryError ):
152+ def __init__ (self , line : int , column : int , key : str ):
153+ hint = f"key { key } is not valid"
154+ super ().__init__ (text = "Key Error" , line = line , column = column , exit_code = 14 , hint = hint )
155+
156+ class IndexError (MemoryError ):
157+ def __init__ (self , line : int , column : int , index : int ):
158+ hint = f"Index { index } out of range"
159+ super ().__init__ (text = "Index Error" , line = line , column = column , exit_code = 15 , hint = hint )
160+
161+
162+ class ArithmeticError (RuntimeError ):
163+ def __init__ (self , line : int , column : int , exit_code = 16 , hint = "" ):
164+ if hint : print (hint )
165+ super ().__init__ (text = "Arithmetic Error" , line = line , column = column , exit_code = exit_code )
166+
167+
168+ class DivisionByZeroError (ArithmeticError ):
169+ def __init__ (self , line : int , column : int ):
170+ super ().__init__ (line = line , column = column , exit_code = 17 , hint = "Division by Zero" )
171+
172+
173+ class FloatingPointError (ArithmeticError ):
174+ def __init__ (self , line : int , column : int ):
175+ super ().__init__ (line = line , column = column , exit_code = 18 , hint = "Floating Point Error" )
176+
177+
178+ class TestError (RuntimeError ):
179+ def __init__ (self , line : int , column : int , test_number : int ):
180+ super ().__init__ (text = f"Test { test_number } failed" , line = line , column = column , exit_code = 19 )
181+
182+
183+ class OSError (Error ):
184+ def __init__ (self , line : int , column : int , function_name : str ):
185+ print (f"there was an Error in function { function_name } " )
186+ super ().__init__ (text = "OS Error" , line = line , column = column , exit_code = 20 )
187+
188+
189+ class KeyboardInterrupt (Error ):
190+ def __init__ (self , line : int , column : int ):
191+ super ().__init__ (text = "Keyboard Interrupt" , line = line , column = column , exit_code = 21 )
192+
193+
194+ class OverflowError (Error ):
195+ def __init__ (self , line : int , column : int , exit_code = 22 , text = "Overflow Error" , hint = "" ):
196+ if hint : print (hint )
197+ super ().__init__ (text = text , line = line , column = column , exit_code = exit_code )
198+
199+
200+ class RecursionError (OverflowError ):
201+ def __init__ (self , line : int , column : int , depth : int ):
202+ super ().__init__ (line = line , column = column , exit_code = 23 , text = "Recursion Error" , hint = f"Max recursion depth { depth } reached" )
203+
204+
205+ class NumberOverflow (OverflowError ):
206+ def __init__ (self , line : int , column : int , type ):
207+ hint = f"Number Overflow for Type { type } "
208+ super ().__init__ (line = line , column = column , exit_code = 24 , text = "Number Overflow" , hint = hint )
209+
210+
211+ class BufferError (RuntimeError ):
212+ def __init__ (self , line : int , column : int ):
213+ super ().__init__ (text = "Buffer Error" , line = line , column = column , exit_code = 25 )
85214
86215
87216####################
0 commit comments