00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import "CPCoder.j"
00024 @import "CPObject.j"
00025 @import "CPString.j"
00026
00027
00028 CPInvalidArgumentException = "CPInvalidArgumentException";
00029 CPUnsupportedMethodException = "CPUnsupportedMethodException";
00030 CPRangeException = "CPRangeException";
00031 CPInternalInconsistencyException = "CPInternalInconsistencyException";
00032
00047 @implementation CPException : CPObject
00048 {
00049 id _userInfo;
00050 }
00051
00052
00053
00054
00055 + (id)alloc
00056 {
00057 return new Error();
00058 }
00059
00065 + (void)raise:(CPString)aName reason:(CPString)aReason
00066 {
00067 [[self exceptionWithName:aName reason:aReason userInfo:nil] raise];
00068 }
00069
00077 + (CPException)exceptionWithName:(CPString)aName reason:(CPString)aReason userInfo:(CPDictionary)aUserInfo
00078 {
00079 return [[self alloc] initWithName:aName reason:aReason userInfo:aUserInfo];
00080 }
00081
00089 - (id)initWithName:(CPString)aName reason:(CPString)aReason userInfo:(CPDictionary)aUserInfo
00090 {
00091 self = [super init];
00092
00093 if (self)
00094 {
00095 name = aName;
00096 message = aReason;
00097 _userInfo = aUserInfo;
00098 }
00099
00100 return self;
00101 }
00102
00106 - (CPString)name
00107 {
00108 return name;
00109 }
00110
00114 - (CPString)reason
00115 {
00116 return message;
00117 }
00118
00122 - (CPDictionary)userInfo
00123 {
00124 return _userInfo;
00125 }
00126
00130 - (CPString)description
00131 {
00132 return message;
00133 }
00134
00138 - (void)raise
00139 {
00140 throw self;
00141 }
00142
00143 @end
00144
00145 @implementation CPException (CPCopying)
00146
00147 - (id)copy
00148 {
00149 return [[self class] exceptionWithName:name reason:message userInfo:_userInfo];
00150 }
00151
00152 @end
00153
00154 var CPExceptionNameKey = "CPExceptionNameKey",
00155 CPExceptionReasonKey = "CPExceptionReasonKey",
00156 CPExceptionUserInfoKey = "CPExceptionUserInfoKey";
00157
00158 @implementation CPException (CPCoding)
00159
00165 - (id)initWithCoder:(CPCoder)aCoder
00166 {
00167 self = [super init];
00168
00169 if (self)
00170 {
00171 name = [aCoder decodeObjectForKey:CPExceptionNameKey];
00172 message = [aCoder decodeObjectForKey:CPExceptionReasonKey];
00173 _userInfo = [aCoder decodeObjectForKey:CPExceptionUserInfoKey];
00174 }
00175
00176 return self;
00177 }
00178
00183 - (void)encodeWithCoder:(CPCoder)aCoder
00184 {
00185 [aCoder encodeObject:name forKey:CPExceptionNameKey];
00186 [aCoder encodeObject:message forKey:CPExceptionReasonKey];
00187 [aCoder encodeObject:_userInfo forKey:CPExceptionUserInfoKey];
00188 }
00189
00190 @end
00191
00192
00193
00194 Error.prototype.isa = CPException;
00195 Error.prototype._userInfo = NULL;
00196
00197 [CPException initialize];
00198
00199 function _CPRaiseInvalidAbstractInvocation(anObject, aSelector)
00200 {
00201 [CPException raise:CPInvalidArgumentException reason:@"*** -" + sel_getName(aSelector) + @" cannot be sent to an abstract object of class " + [anObject className] + @": Create a concrete instance!"];
00202 }
00203
00204 function _CPReportLenientDeprecation( aClass, oldSelector, newSelector)
00205 {
00206 CPLog.warn("[" + CPStringFromClass(aClass) + " " + CPStringFromSelector(oldSelector) + "] is deprecated, using " + CPStringFromSelector(newSelector) + " instead.");
00207 }