-
Notifications
You must be signed in to change notification settings - Fork 2
/
exception.py
46 lines (37 loc) · 1.59 KB
/
exception.py
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
38
39
40
41
42
43
44
45
46
class SchemeError(Exception):
pass
# Unbound variable
class UnboundVariableError(SchemeError):
def __init__(self, var):
self.msg = "Unbound variable {0}".format(var)
# IllegalArgumentErrors
class IllegalArgumentError(SchemeError):
pass
# Bad number of arguments
class ArgumentCountError(IllegalArgumentError):
def __init__(self, function, expected, given):
self.msg = "Bad number of arguments: {0} takes {1} arguments ({2} given)".format(function, expected, given)
# Wrong type of argument
class WrongArgumentTypeError(IllegalArgumentError):
def __init__(self, function, expected, given):
self.msg = "Wrong type of argument for {0}: Expected {1} ({2} given)".format(function, expected, given)
# Index out of bounds
class IndexOutOfBoundsError(SchemeError):
def __init__(self, vector, index, length):
self.msg = "Index out of bounds: Tried to access index {1} of {0} (with length {2})".format(vector, index, length)
# Mismatched Parens
class MismatchedParensError(SchemeError):
def __init__(self, expression):
self.msg = "Mismatched parenthesis: {0}".format(expression)
# Parse Error
class ParseError(SchemeError):
def __init__(self, token):
self.msg = "Error: Unidentified token {0}".format(token)
# Trace Error
class TraceError(SchemeError):
def __init__(self, expression, reason):
self.msg = "Error: Cannot trace {0}: {1}".format(expression, reason)
# Untrace Error
class UntraceError(SchemeError):
def __init__(self, expression, reason):
self.msg = "Error: Cannot untrace {0}: {1}".format(expression. reason)