• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//
2//  RuntimeException.m
3//  ANTLR
4//
5//  Created by Alan Condit on 6/5/10.
6// [The "BSD licence"]
7// Copyright (c) 2010 Alan Condit
8// All rights reserved.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions
12// are met:
13// 1. Redistributions of source code must retain the above copyright
14//    notice, this list of conditions and the following disclaimer.
15// 2. Redistributions in binary form must reproduce the above copyright
16//    notice, this list of conditions and the following disclaimer in the
17//    documentation and/or other materials provided with the distribution.
18// 3. The name of the author may not be used to endorse or promote products
19//    derived from this software without specific prior written permission.
20//
21// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32#import "RuntimeException.h"
33
34
35@implementation RuntimeException
36
37+ (id) newException
38{
39    return [[RuntimeException alloc] init];
40}
41
42+ (id) newException:(NSString *)aReason
43{
44    return [[RuntimeException alloc] init:aReason];
45}
46
47+ (id) newException:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
48{
49    return [[RuntimeException alloc] init:aReason userInfo:aUserInfo];
50}
51
52+ (id) newException:(NSString *)aName reason:(NSString *)aReason;
53{
54    return [[RuntimeException alloc] initWithName:aName reason:aReason];
55}
56
57+ (id) newException:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo;
58{
59    return [[RuntimeException alloc] initWithName:aName reason:aReason userInfo:aUserInfo];
60}
61
62
63- (id) init
64{
65    self = [super initWithName:@"RuntimeException" reason:@"UnknownException" userInfo:nil];
66    return(self);
67}
68
69- (id) init:(NSString *)aReason
70{
71    self = [super initWithName:(NSString *)@"RuntimeException" reason:(NSString *)aReason userInfo:(NSDictionary *)nil];
72    return(self);
73}
74
75- (id) init:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
76{
77    self = [super initWithName:@"RuntimeException" reason:aReason userInfo:aUserInfo];
78    return(self);
79}
80
81- (id) initWithName:(NSString *)aName reason:(NSString *)aReason
82{
83    self = [super initWithName:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)nil];
84    return(self);
85}
86
87- (id) initWithName:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
88{
89    self = [super initWithName:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo];
90    return(self);
91}
92
93- (NSString *) Description
94{
95    return [super reason];
96}
97
98- (id) stackTrace:(NSException *)e
99{
100    NSArray *addrs = [e callStackReturnAddresses];
101    NSArray *trace = [e callStackSymbols];
102
103    for (NSString *traceStr in trace) {
104        NSLog( @"%@", traceStr);
105        // TODO: remove special after testing
106        if ([traceStr hasPrefix:@"main("] > 0)
107            return traceStr;
108        if (![traceStr hasPrefix:@"org.stringtemplate"])
109            return traceStr;
110    }
111    return trace;
112}
113
114@end
115
116@implementation CloneNotSupportedException
117
118+ (id) newException
119{
120    return [[CloneNotSupportedException alloc] init];
121}
122
123+ (id) newException:(NSString *)aReason
124{
125    return [[CloneNotSupportedException alloc] init:aReason];
126}
127
128+ (id) newException:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
129{
130    return [[CloneNotSupportedException alloc] init:aReason userInfo:aUserInfo];
131}
132
133- (id) init
134{
135    self = [super initWithName:@"CloneNotSupportedException" reason:@"Attempted to clone non-cloneable object" userInfo:nil];
136    return(self);
137}
138
139- (id) init:(NSString *)aReason
140{
141    self = [super initWithName:@"CloneNotSupportedException" reason:(NSString *)aReason userInfo:nil];
142    return(self);
143}
144
145- (id) init:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
146{
147    self = [super initWithName:@"CloneNotSupportedException" reason:aReason userInfo:aUserInfo];
148    return(self);
149}
150
151@end
152
153@implementation ConcurrentModificationException
154
155+ (id) newException
156{
157    return [[ConcurrentModificationException alloc] init];
158}
159
160+ (id) newException:(NSString *)aReason
161{
162    return [[ConcurrentModificationException alloc] init:aReason];
163}
164
165+ (id) newException:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
166{
167    return [[ConcurrentModificationException alloc] init:aReason userInfo:aUserInfo];
168}
169
170- (id) init
171{
172    self = [super initWithName:@"ConcurrentModificationException" reason:@"UnknownException" userInfo:nil];
173    return(self);
174}
175
176- (id) init:(NSString *)aReason
177{
178    self = [super initWithName:@"ConcurrentModificationException" reason:(NSString *)aReason userInfo:nil];
179    return(self);
180}
181
182- (id) init:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
183{
184    self = [super initWithName:@"ConcurrentModificationException" reason:aReason userInfo:aUserInfo];
185    return(self);
186}
187
188@end
189
190@implementation IllegalArgumentException
191
192+ (id) newException
193{
194    return [[IllegalArgumentException alloc] init];
195}
196
197+ (id) newException:(NSString *)aReason
198{
199    return [[IllegalArgumentException alloc] init:aReason];
200}
201
202+ (id) newException:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
203{
204    return [[IllegalArgumentException alloc] init:aReason userInfo:aUserInfo];
205}
206
207- (id) init
208{
209    self = [super initWithName:@"IllegalArgumentException" reason:@"IllegalStateException" userInfo:nil];
210    return(self);
211}
212
213- (id) init:(NSString *)aReason
214{
215    self = [super initWithName:@"IllegalArgumentException" reason:(NSString *)aReason userInfo:nil];
216    return(self);
217}
218
219- (id) init:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
220{
221    self = [super initWithName:@"IllegalArgumentException" reason:aReason userInfo:aUserInfo];
222    return(self);
223}
224
225@end
226
227@implementation IllegalStateException
228
229+ (id) newException
230{
231    return [[IllegalStateException alloc] init];
232}
233
234+ (id) newException:(NSString *)aReason
235{
236    return [[IllegalStateException alloc] init:aReason];
237}
238
239+ (id) newException:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
240{
241    return [[IllegalStateException alloc] init:aReason userInfo:aUserInfo];
242}
243
244- (id) init
245{
246    self = [super initWithName:@"IllegalStateException" reason:@"IllegalStateException" userInfo:nil];
247    return(self);
248}
249
250- (id) init:(NSString *)aReason
251{
252    self = [super initWithName:@"IllegalStateException" reason:(NSString *)aReason userInfo:nil];
253    return(self);
254}
255
256- (id) init:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
257{
258    self = [super initWithName:@"IllegalStateException" reason:aReason userInfo:aUserInfo];
259    return(self);
260}
261
262@end
263
264@implementation IndexOutOfBoundsException
265
266+ (id) newException
267{
268    return [[IndexOutOfBoundsException alloc] init];
269}
270
271+ (id) newException:(NSString *)aReason
272{
273    return [[IndexOutOfBoundsException alloc] init:aReason];
274}
275
276+ (id) newException:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
277{
278    return [[IndexOutOfBoundsException alloc] init:aReason userInfo:aUserInfo];
279}
280
281- (id) init
282{
283    self = [super initWithName:@"IndexOutOfBoundsException" reason:@"IndexOutOfBoundsException" userInfo:nil];
284    return(self);
285}
286
287- (id) init:(NSString *)aReason
288{
289    self = [super initWithName:@"IndexOutOfBoundsException" reason:(NSString *)aReason userInfo:nil];
290    return(self);
291}
292
293- (id) init:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
294{
295    self = [super initWithName:@"IndexOutOfBoundsException" reason:aReason userInfo:aUserInfo];
296    return(self);
297}
298
299@end
300
301@implementation NoSuchElementException
302
303+ (id) newException
304{
305    return [[NoSuchElementException alloc] init];
306}
307
308+ (id) newException:(NSString *)aReason
309{
310    return [[NoSuchElementException alloc] init:aReason];
311}
312
313+ (id) newException:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
314{
315    return [[NoSuchElementException alloc] init:aReason userInfo:(NSDictionary *)aUserInfo];
316}
317
318- (id) init
319{
320    self = [super initWithName:@"NoSuchElementException" reason:@"UnknownException" userInfo:nil];
321    return(self);
322}
323
324- (id) init:(NSString *)aReason
325{
326    self = [super initWithName:@"NoSuchElementException" reason:(NSString *)aReason userInfo:(NSDictionary *)nil];
327    return(self);
328}
329
330- (id) init:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
331{
332    self = [super initWithName:@"NoSuchElementException" reason:aReason userInfo:aUserInfo];
333    return(self);
334}
335
336- (id) initWithName:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
337{
338    self = [super initWithName:aName reason:aReason userInfo:aUserInfo];
339    return(self);
340}
341
342@end
343
344@implementation NullPointerException
345
346+ (id) newException
347{
348    return [[NullPointerException alloc] init];
349}
350
351+ (id) newException:(NSString *)aReason
352{
353    return [[NullPointerException alloc] init:aReason];
354}
355
356+ (id) newException:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
357{
358    return [[NullPointerException alloc] init:aReason userInfo:(NSDictionary *)aUserInfo];
359}
360
361- (id) init
362{
363    self = [super initWithName:@"NullPointerException" reason:@"UnknownException" userInfo:nil];
364    return(self);
365}
366
367- (id) init:(NSString *)aReason
368{
369    self = [super initWithName:@"NullPointerException" reason:(NSString *)aReason userInfo:(NSDictionary *)nil];
370    return(self);
371}
372
373- (id) init:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
374{
375    self = [super initWithName:@"NullPointerException" reason:aReason userInfo:aUserInfo];
376    return(self);
377}
378
379@end
380
381@implementation RewriteEarlyExitException
382
383+ (id) newException
384{
385	return [[self alloc] init];
386}
387
388- (id) init
389{
390	self = [super initWithName:@"RewriteEarlyExitException" reason:nil userInfo:nil];
391	return self;
392}
393
394- (id) initWithName:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)aUserInfo
395{
396    self = [super initWithName:aName reason:aReason userInfo:aUserInfo];
397    return(self);
398}
399
400- (NSString *) description
401{
402	return [self name];
403}
404
405@end
406
407@implementation UnsupportedOperationException
408
409+ (id) newException:(NSString *)aReason
410{
411    return [[RuntimeException alloc] initWithName:@"Unsupported Operation Exception" reason:aReason userInfo:nil];
412}
413
414- (id) initWithName:(NSString *)aName reason:(NSString *)aReason
415{
416    self=[super initWithName:aName reason:aReason userInfo:nil];
417    return self;
418}
419
420- (id) initWithName:(NSString *)aName reason:(NSString *)aReason userInfo:(NSDictionary *)userInfo
421{
422    self=[super initWithName:aName reason:aReason userInfo:userInfo];
423    return self;
424}
425
426@end
427
428