-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception.py
More file actions
41 lines (40 loc) · 1.29 KB
/
exception.py
File metadata and controls
41 lines (40 loc) · 1.29 KB
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
def throw_exception(kind, msg):
"""
Throws a Capacita exception and exits the program.
"""
print(kind + ' exception')
print(msg)
exit()
def throw_exception_with_line(kind, msg, line_mgr, prgm_counter):
print('Error: ' + kind + ' exception')
print(msg)
if line_mgr is None or prgm_counter >= len(line_mgr):
exit()
line_data = line_mgr.get_line_data(prgm_counter)
print('Original source code:')
# First line is considered 'line 1', not 'line 0'
if line_data.line_num == line_data.end_line_num:
print(' Line {0}: {1}'.format(line_data.line_num + 1, line_mgr[prgm_counter]))
else:
print(' Line {0}-{1}: {2}'.format(
line_data.line_num + 1,
line_data.end_line_num + 1,
line_mgr[prgm_counter]
))
print('Internal code:')
low = prgm_counter - 3
high = prgm_counter + 3
if low < 0:
low = 0
if high >= len(line_mgr):
high = len(line_mgr) - 1
for i in xrange(low, high + 1):
if len(line_mgr[i]) == 0:
line = ':no_operation'
else:
line = line_mgr[i]
if i == prgm_counter:
print('--> Line {0}: {1}'.format(i + 1, line))
else:
print(' Line {0}: {1}'.format(i + 1, line))
exit()