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
00043 @implementation CPException : CPObject
00044 {
00045 }
00046
00047
00048
00049
00050 + (id)alloc
00051 {
00052 return new objj_exception();
00053 }
00054
00060 + (void)raise:(CPString)aName reason:(CPString)aReason
00061 {
00062 [[self exceptionWithName:aName reason:aReason userInfo:nil] raise];
00063 }
00064
00072 + (CPException)exceptionWithName:(CPString)aName reason:(CPString)aReason userInfo:(CPDictionary)aUserInfo
00073 {
00074 return [[self alloc] initWithName:aName reason:aReason userInfo:aUserInfo];
00075 }
00076
00084 - (id)initWithName:(CPString)aName reason:(CPString)aReason userInfo:(CPDictionary)aUserInfo
00085 {
00086 self = [super init];
00087
00088 if (self)
00089 {
00090 name = aName;
00091 reason = aReason;
00092 userInfo = aUserInfo;
00093 }
00094
00095 return self;
00096 }
00097
00101 - (CPString)name
00102 {
00103 return name;
00104 }
00105
00109 - (CPString)reason
00110 {
00111 return reason;
00112 }
00113
00117 - (CPDictionary)userInfo
00118 {
00119 return userInfo;
00120 }
00121
00125 - (CPString)description
00126 {
00127 return reason;
00128 }
00129
00133 - (void)raise
00134 {
00135 objj_exception_throw(self);
00136 }
00137
00138 @end
00139
00140 @implementation CPException (CPCopying)
00141
00142 - (id)copy
00143 {
00144 return [[self class] exceptionWithName:name reason:reason userInfo:userInfo];
00145 }
00146
00147 @end
00148
00149 @implementation CPException (CPCoding)
00150
00156 - (id)initWithCoder:(CPCoder)aCoder
00157 {
00158 self = [super init];
00159
00160 if (self)
00161 {
00162 name = [aCoder decodeObjectForKey:CPExceptionNameKey];
00163 reason = [aCoder decodeObjectForKey:CPExceptionReasonKey];
00164 userInfo = [aCoer decodeObjectForKey:CPExceptionUserInfoKey];
00165 }
00166
00167 return self;
00168 }
00169
00174 - (void)encodeWithCoder:(CPCoder)aCoder
00175 {
00176 [aCoder encodeObject:name forKey:CPExceptionNameKey];
00177 [aCoder encodeObject:reason forKey:CPExceptionReasonKey];
00178 [aCoder encodeObject:userInfo forKey:CPExceptionUserInfoKey];
00179 }
00180
00181 @end
00182
00183 objj_exception.prototype.isa = CPException;
00184 [CPException initialize];
00185
00186 function _CPRaiseInvalidAbstractInvocation(anObject, aSelector)
00187 {
00188 [CPException raise:CPInvalidArgumentException reason:@"*** -" + sel_getName(aSelector) + @" cannot be sent to an abstract object of class " + [anObject className] + @": Create a concrete instance!"];
00189 }