-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexcept.monkey
170 lines (129 loc) · 3.37 KB
/
except.monkey
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
Strict
Public
' Imports (Private):
Private
Import regal.typetool
Import regal.retrostrings
Import brl.stream
Import brl.databuffer
Import bufferview
Public
' Classes:
#Rem
Class Exception Extends Throwable
' ...
End
#End
' This is used to catch (And throw) an unspecific allocation exception.
Class AllocationException Extends Throwable
' Constructor(s):
Method New(RequestedSize:UInt)
Self.RequestedSize = RequestedSize
End
' Methods:
Method ToString:String()
Return "An error occurred while allocating a dynamic area of memory. {" + RequestedSize + " bytes}"
End
' Fields:
Field RequestedSize:UInt
End
' This is used to catch (And throw) specific allocation exceptions.
Class BulkAllocationException<ContainerType> Extends AllocationException
' Global variable(s) (Private):
Private
Global NIL:ContainerType
Public
' Constructor(s):
Method New(Data:ContainerType=NIL, Size:UInt)
Super.New(Size)
Self.Data = Data
End
' Fields:
Field Data:ContainerType
End
Class InvalidViewOperation Extends Throwable Abstract ' InvalidBufferViewOperation
' Functions:
Function ConvertAddress:String(Address:UInt)
Return HexBE(Address)
End
' Constructor(s):
Method New(View:BufferView, Address:UInt, Count:UInt=0)
Self.View = View
Self.Address = Address
Self.Count = Count
End
' Methods:
Method ToString:String() Abstract
' This reports the number of bytes the operation intended to work with.
Method PostCount:String()
Return "{" + Count + " bytes}"
End
' Fields:
Field View:BufferView
Field Address:UInt
Field Count:UInt
End
Class InvalidViewMappingOperation Extends InvalidViewOperation
' Constructor(s):
Method New(View:BufferView, Offset:UInt, Count:UInt)
Super.New(View, Offset, Count)
End
' Methods:
Method ToString:String()
Local Message:= "Failed to map a memory view at: " + ConvertAddress(Address)
If (Count > 0) Then
Return (Message + PostCount())
Endif
Return Message
End
End
Class InvalidViewReadOperation Extends InvalidViewOperation ' InvalidBufferViewReadOperation
' Constructor(s):
Method New(View:BufferView, Address:UInt, Count:UInt=0)
Super.New(View, Address, Count)
End
' Methods:
Method ToString:String()
Local Message:= "Attempted to read from invalid local memory address: " + ConvertAddress(Address)
If (Count > 0) Then
Return (Message + PostCount())
Endif
Return Message
End
End
Class InvalidViewWriteOperation Extends InvalidViewOperation ' InvalidBufferViewWriteOperation
' Constructor(s):
Method New(View:BufferView, Address:UInt, Count:UInt=0)
Super.New(View, Address, Count)
End
' Methods:
Method ToString:String()
Local Message:= "Attempted to perform an invalid write-operation on local address: " + ConvertAddress(Address)
If (Count > 0) Then
Return (Message + PostCount())
Endif
Return Message
End
End
Class StreamTransferException Extends StreamError
' Constructor(s):
Method New(S:Stream=Null, TransferSize:UInt)
Super.New(S)
Self.TransferSize = TransferSize
End
' Methods:
Method ToString:String()
Return "Failed to perform stream transfer operation. {" + TransferSize + " bytes}"
End
' Fields:
Field TransferSize:UInt
End
Class StreamUnavailableException Extends StreamError
' Constructor(s):
Method New(S:Stream=Null)
Super.New(S)
End
Method ToString:String()
Return "Unable to find valid stream instance(s)."
End
End