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
00045 @implementation CPException : CPObject
00046 {
00047 }
00048
00049
00050
00051
00052 + (id)alloc
00053 {
00054 return new objj_exception();
00055 }
00056
00062 + (void)raise:(CPString)aName reason:(CPString)aReason
00063 {
00064 [[self exceptionWithName:aName reason:aReason userInfo:nil] raise];
00065 }
00066
00074 + (CPException)exceptionWithName:(CPString)aName reason:(CPString)aReason userInfo:(CPDictionary)aUserInfo
00075 {
00076 return [[self alloc] initWithName:aName reason:aReason userInfo:aUserInfo];
00077 }
00078
00086 - (id)initWithName:(CPString)aName reason:(CPString)aReason userInfo:(CPDictionary)aUserInfo
00087 {
00088 self = [super init];
00089
00090 if (self)
00091 {
00092 name = aName;
00093 reason = aReason;
00094 userInfo = aUserInfo;
00095 }
00096
00097 return self;
00098 }
00099
00103 - (CPString)name
00104 {
00105 return name;
00106 }
00107
00111 - (CPString)reason
00112 {
00113 return reason;
00114 }
00115
00119 - (CPDictionary)userInfo
00120 {
00121 return userInfo;
00122 }
00123
00127 - (CPString)description
00128 {
00129 return reason;
00130 }
00131
00135 - (void)raise
00136 {
00137 objj_exception_throw(self);
00138 }
00139
00140 @end
00141
00142 @implementation CPException (CPCopying)
00143
00144 - (id)copy
00145 {
00146 return [[self class] exceptionWithName:name reason:reason userInfo:userInfo];
00147 }
00148
00149 @end
00150
00151 var CPExceptionNameKey = "CPExceptionNameKey",
00152 CPExceptionReasonKey = "CPExceptionReasonKey",
00153 CPExceptionUserInfoKey = "CPExceptionUserInfoKey";
00154
00155 @implementation CPException (CPCoding)
00156
00162 - (id)initWithCoder:(CPCoder)aCoder
00163 {
00164 self = [super init];
00165
00166 if (self)
00167 {
00168 name = [aCoder decodeObjectForKey:CPExceptionNameKey];
00169 reason = [aCoder decodeObjectForKey:CPExceptionReasonKey];
00170 userInfo = [aCoder decodeObjectForKey:CPExceptionUserInfoKey];
00171 }
00172
00173 return self;
00174 }
00175
00180 - (void)encodeWithCoder:(CPCoder)aCoder
00181 {
00182 [aCoder encodeObject:name forKey:CPExceptionNameKey];
00183 [aCoder encodeObject:reason forKey:CPExceptionReasonKey];
00184 [aCoder encodeObject:userInfo forKey:CPExceptionUserInfoKey];
00185 }
00186
00187 @end
00188
00189 objj_exception.prototype.isa = CPException;
00190 [CPException initialize];
00191
00192 function _CPRaiseInvalidAbstractInvocation(anObject, aSelector)
00193 {
00194 [CPException raise:CPInvalidArgumentException reason:@"*** -" + sel_getName(aSelector) + @" cannot be sent to an abstract object of class " + [anObject className] + @": Create a concrete instance!"];
00195 }