Mercurial > projects > dstep
annotate dstep/foundation/NSException.d @ 15:7ff919f595d5
Added the Foundation framework, again
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 03 Aug 2009 15:31:48 +0200 |
parents | 89f3c3ef1fd2 |
children | 19885b43130e |
rev | line source |
---|---|
14 | 1 /** |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Aug 3, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.foundation.NSException; | |
8 | |
9 import dstep.foundation.NSArray; | |
10 import dstep.foundation.NSAssertionHandler; | |
11 import dstep.foundation.NSDictionary; | |
12 import dstep.foundation.NSObject; | |
13 import dstep.foundation.NSString; | |
14 import dstep.objc.bridge.Bridge; | |
15 import dstep.objc.objc : id; | |
16 import dstep.setjmp; | |
17 import dstep.stdarg; | |
18 | |
19 import bindings = dstep.foundation.NSException_bindings; | |
20 | |
21 extern (C) | |
22 { | |
23 alias void function (id) NSUncaughtExceptionHandler *; | |
24 } | |
25 | |
26 const NSString NSGenericException; | |
27 const NSString NSRangeException; | |
28 const NSString NSInvalidArgumentException; | |
29 const NSString NSInternalInconsistencyException; | |
30 const NSString NSMallocException; | |
31 const NSString NSObjectInaccessibleException; | |
32 const NSString NSObjectNotAvailableException; | |
33 const NSString NSDestinationInvalidException; | |
34 const NSString NSPortTimeoutException; | |
35 const NSString NSInvalidSendPortException; | |
36 const NSString NSInvalidReceivePortException; | |
37 const NSString NSPortSendException; | |
38 const NSString NSPortReceiveException; | |
39 const NSString NSOldStyleException; | |
40 | |
41 static this () | |
42 { | |
43 NSGenericException = new NSString(bindings.NSGenericException); | |
44 NSRangeException = new NSString(bindings.NSRangeException); | |
45 NSInvalidArgumentException = new NSString(bindings.NSInvalidArgumentException); | |
46 NSInternalInconsistencyException = new NSString(bindings.NSInternalInconsistencyException); | |
47 NSMallocException = new NSString(bindings.NSMallocException); | |
48 NSObjectInaccessibleException = new NSString(bindings.NSObjectInaccessibleException); | |
49 NSObjectNotAvailableException = new NSString(bindings.NSObjectNotAvailableException); | |
50 NSDestinationInvalidException = new NSString(bindings.NSDestinationInvalidException); | |
51 NSPortTimeoutException = new NSString(bindings.NSPortTimeoutException); | |
52 NSInvalidSendPortException = new NSString(bindings.NSInvalidSendPortException); | |
53 NSInvalidReceivePortException = new NSString(bindings.NSInvalidReceivePortException); | |
54 NSPortSendException = new NSString(bindings.NSPortSendException); | |
55 NSPortReceiveException = new NSString(bindings.NSPortReceiveException); | |
56 NSOldStyleException = new NSString(bindings.NSOldStyleException); | |
57 } | |
58 | |
59 class NSAssertionHandler : NSObject | |
60 { | |
61 mixin ObjcWrap; | |
62 | |
63 static NSAssertionHandler currentHandler () | |
64 { | |
15
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
65 return invokeObjcSelfClass!(NSAssertionHandler, "currentHandler"); |
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
66 } |
14 | 67 |
68 void handleFailureInMethod (SEL selector, Object object, NSString fileName, NSInteger line, NSString description, ...) | |
69 { | |
70 return invokeObjcSelf!(void, "handleFailureInMethod:object:file:lineNumber:description:", SEL, Object, NSString, NSInteger, NSString)(selector, object, fileName, line, description); | |
71 } | |
72 | |
73 void handleFailureInFunction (NSString functionName, NSString fileName, NSInteger line, NSString description, ...) | |
74 { | |
75 return invokeObjcSelf!(void, "handleFailureInFunction:file:lineNumber:description:", NSString, NSString, NSInteger, NSString)(functionName, fileName, line, description); | |
76 } | |
77 } | |
78 | |
79 class NSException : NSObject, INSCopying, INSCoding | |
80 { | |
81 mixin ObjcWrap; | |
82 mixin TNSExceptionRaisingConveniences; | |
83 | |
84 static NSException exceptionWithName (NSString name, NSString reason, NSDictionary userInfo) | |
85 { | |
15
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
86 return invokeObjcSelfClass!(NSException, "exceptionWithName:reason:userInfo:", NSString, NSString, NSDictionary)(name, reason, userInfo); |
7ff919f595d5
Added the Foundation framework, again
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
87 } |
14 | 88 |
89 Object initWithName (NSString aName, NSString aReason, NSDictionary aUserInfo) | |
90 { | |
91 return invokeObjcSelf!(Object, "initWithName:reason:userInfo:", NSString, NSString, NSDictionary)(aName, aReason, aUserInfo); | |
92 } | |
93 | |
94 this (NSString aName, NSString aReason, NSDictionary aUserInfo) | |
95 { | |
96 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
97 id result = Bridge.invokeObjcMethod!(id, "initWithName:reason:userInfo:", NSString, NSString, NSDictionary)(objcObject, aName, aReason, aUserInfo); | |
98 | |
99 if (result) | |
100 objcObject = ret; | |
101 | |
102 dObject = this; | |
103 } | |
104 | |
105 NSString name () | |
106 { | |
107 return invokeObjcSelf!(NSString, "name"); | |
108 } | |
109 | |
110 NSString reason () | |
111 { | |
112 return invokeObjcSelf!(NSString, "reason"); | |
113 } | |
114 | |
115 NSDictionary userInfo () | |
116 { | |
117 return invokeObjcSelf!(NSDictionary, "userInfo"); | |
118 } | |
119 | |
120 NSArray callStackReturnAddresses () | |
121 { | |
122 return invokeObjcSelf!(NSArray, "callStackReturnAddresses"); | |
123 } | |
124 | |
125 void raise () | |
126 { | |
127 return invokeObjcSelf!(void, "raise"); | |
128 } | |
129 | |
130 Object copyWithZone (NSZone* zone) | |
131 { | |
132 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone); | |
133 } | |
134 | |
135 void encodeWithCoder (NSCoder aCoder) | |
136 { | |
137 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder); | |
138 } | |
139 | |
140 Object initWithCoder (NSCoder aDecoder) | |
141 { | |
142 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder); | |
143 } | |
144 | |
145 this (NSCoder aDecoder) | |
146 { | |
147 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass); | |
148 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder); | |
149 | |
150 if (result) | |
151 objcObject = ret; | |
152 | |
153 dObject = this; | |
154 } | |
155 } | |
156 | |
157 template TNSExceptionRaisingConveniences () | |
158 { | |
159 static void raise (NSString name, NSString format, ...) | |
160 { | |
161 return invokeObjcSelfClass!(void, "raise:format:", NSString, NSString)(name, format); | |
162 } | |
163 | |
164 static void raise (NSString name, NSString format, char* argList) | |
165 { | |
166 return invokeObjcSelfClass!(void, "raise:format:arguments:", NSString, NSString, char*)(name, format, argList); | |
167 } | |
168 } | |
169 | |
170 extern (C) | |
171 { | |
172 NSUncaughtExceptionHandler* NSGetUncaughtExceptionHandler (); | |
173 void NSSetUncaughtExceptionHandler (NSUncaughtExceptionHandler* dummy); | |
174 } |